Adding Post ID's to returned results

Forums › Forums › Search & Filter Pro › Adding Post ID's to returned results

Viewing 2 posts – 1 through 2 (of 2 total)
  • Anonymous
    #41013

    Hi,

    Is it possible to specify an array of posts ID’s to include in the returned search results?

    I used to use pre_get_posts to do this, modifying the ‘post__in’ query variable with my array, but it looks as though ‘post__in’ cannot be used anymore when filter a query?

    I have seen that since the development of the cache a few additional hooks have been introduced (such as sf_edit_query_args), but I’ve not be able to use ‘post__in’ with any of these (although I can use ‘p’ to specify a single post).

    Could you point me into the direction of how I could add extra post ID’s into my results?

    Thanks for your help 😀

    Matt

    Ross Moderator
    #41395

    Hey Matt

    This is pretty tricky actually.

    Since the introduction of the cache, most queries are sent off to the cache DB, and they return a number of IDs… which are placed inside the post__in field in a query.

    So, I’m actually scratching my head as to how we could do this.

    There is a filter for modifying the query:

    http://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Edit_Query_Arguments

    add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );

    Which should be used like:

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==225)
    	{
    		//modify $query_args here before returning it
    		$query_args['post__in'] = array(1,2,3,4);
    	}
    	
    	return $query_args;
    }

    Which S&F also uses for setting up the query – and will probbably overeride this withe the results from the S&F cache.

    Try initializing hook much later (so S&F has finished with the post__in var):

    add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 200 );

    Thanks

Viewing 2 posts – 1 through 2 (of 2 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.