Forums › Forums › Search & Filter Pro › Adding Post ID's to returned results
Tagged: post__in, pre get posts, sf_edit_query_args
- This topic has 1 reply, 2 voices, and was last updated 8 years, 7 months ago by Ross.
-
Anonymous(Private) March 30, 2016 at 3:44 pm #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(Private) April 3, 2016 at 1:41 pm #41395Hey 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:
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
-
AuthorPosts