Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: [Resolved] Limiting Activities by User’s City

@puffyjoe

Participant

I just wanted to say I got it working. this is my code to filter by the city I save in meta

	public function activity_querystring_filter( $query_string = '', $object = '' ) 
	{
		
	    if( $object != 'activity' )
		return $query_string;
	 
	    // You can easily manipulate the query string
	    // by transforming it into an array and merging
	    // arguments with these default ones
	    $args = wp_parse_args( $query_string, array(
		'action'  => false,
		'type'    => false,
		'user_id' => false,
		'page'    => 1
	    ) );
	 
	    if( bp_is_user() )
	    	    $args['user_id'] = bp_displayed_user_id();
 
	  
	   // try to use args  $user_id = bp_loggedin_user_id();
	   
	    $user_id = bp_loggedin_user_id();
	    $city = xprofile_get_field_data('9', $user_id);
	    //   $city = xprofile_get_field_data('9', $args['user_id']);  //not sure if this is set right but could work
	    
	    
	    // An activity meta query <img src="https://codex.buddypress.org/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;">
	    $args['meta_query'] = array(
		 array(
		 	 /* this is the meta_key you want to filter on */
			'key'     => 'city',
			/* You need to get all values that are >= to 1 */
			'value'   => $city,
			'type'    => 'CHAR',
			'compare' => '='
		    ),
		);
	 
	    $query_string = empty( $args ) ? $query_string : $args;
	  
	 
	    return apply_filters( 'bp_plugin_activity_querystring_filter', $query_string, $object );
	}//end method activity_querystring_filter 
Skip to toolbar