Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Filter Query Args

Viewing 10 posts - 1 through 10 (of 24 total)
  • Christopher Bessler
    #37123

    Hello Support,
    I’m trying to filter search results based on a taxonomy item. I’m trying to this code that I found in the forum, but I can’t get it to work even just using $query_args[‘order’] = ‘desc’;

    What am I doing wrong here? Below is the the code I’ve been trying.

    function sf_filter_query_args( $query_args, $sfid ) {

    if($sfid==3906) {
    $query_args[‘member-category’] = get_queried_object()->name;
    //$query_args[‘order’] = ‘desc’;
    }
    return $query_args;
    }

    add_filter( ‘sf_edit_query_args’, ‘sf_filter_query_args’, 10, 2 );

    Christopher Bessler
    #37151

    OK,
    I’m able to get this to filter:

    function member_query_args( $query_args, $sfid ) {

    if($sfid==3906) {
    $query_args = array(
    ‘member-category’ => ‘hotels-motels’
    );
    }
    return $query_args;
    }

    How can I go about dynamically placing the value of member-category ?

    add_filter( ‘sf_edit_query_args’, ‘member_query_args’, 10, 2 );

    Ross Moderator
    #37160

    Hey there

    It really depends on how you would detect the current “memeber-category”?

    Thanks

    Christopher Bessler
    #37173

    Hi Ross,
    the search is being performed from the taxonomy-member-category.php template. My whole goal is to be able to only search posts/content from within the current member-category.

    Ross Moderator
    #37201

    Hi Christopher

    So the question is, how do you detect the “current member-category”.

    This is nothing to do with S&F – its something in your setup you need to figure out.

    “How do I get the current member category in to a variable?”

    Because once you can do this, you can add it to the code above:

    function member_query_args( $query_args, $sfid ) {
    
    	$current_member_category = get_current_member_category();
    	
    	if(empty($current_member_category))
    	{ // so some kind of sanity check to make sure we got one
    		return $query_args;
    	}
    	
    	if($sfid==3906) {
    		$query_args = array(
    			'member-category' => $current_member_category
    		);
    	}
    	return $query_args;
    }

    Now here, I made up a function get_current_member_category – this is something you would have to implement yourself – as I have no idea how to do something so specific in your environment.

    Thanks

    Ross Moderator
    #37202
    Christopher Bessler
    #37240

    Hi Ross,
    thanks for all of the great input. Would this function run from the taxonomy-member-category.php template where the shortcode is placed or would it be happening on the search.php template? I believe the get_queried_object()->term_id; would only work if the query filter were taking place on the taxonomy-member-category.php template.

    Maybe it would work if the search never left taxonomy-member-category.php template. Is there a way of having search results display within the same page that the search is happening?

    Christopher Bessler
    #37242

    Ross,
    I just tested this and found that if I display results using the search.php then the filter can’t use the get_queried_object()->name; , but if I display results using the shortcode method within the same taxonomy template, the get_queried_object()->name; is usable for the query filter.

    Here’s what I currently have:

    function member_query_args( $query_args, $sfid ) {
    	
    	$current_member_category = get_queried_object()->name;
    	
      if($sfid==3906) {
    	 $query_args = array(
        'member-category' => $current_member_category
    	);
      }
      return $query_args;
    }
    
    add_filter( 'sf_edit_query_args', 'member_query_args', 10, 2 );
    Christopher Bessler
    #37257

    So the query filter only seems to work until a search is made or pagination is selected. See my link below. I am currently using S&F to display the posts.

    As soon as you make a search, it no longer filters by the current member-category. In this example only posts in hotels and motels are being queried until the search takes place.

    http://selkirkloop.org/wordpress/member-category/lodging/hotels-motels/

    Christopher Bessler
    #37268

    Update: pagination appears to be working.

    If Member Regions taxonomy on http://selkirkloop.org/wordpress/member-category/lodging/hotels-motels/ is dropped down the accurate count shows until an option is selected. As soon as an option is selected, the search reverts back to searching all posts instead of the filtered $current_member_category .

Viewing 10 posts - 1 through 10 (of 24 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.