Forums › Forums › Search & Filter Pro › Modify results query if specific taxonomy is selected
- This topic has 3 replies, 3 voices, and was last updated 5 years, 5 months ago by Ross.
-
Anonymous(Private) May 14, 2019 at 12:14 pm #211117
Hello.
I would like to add upon defined array of posts in front of all results if specific custom taxonomy is selected in search terms, however I don’t know where to start and documentation wasn’t helpful enough.
I think I somehow had to use filter ‘sf_filter_query_args’, but thats all I could determined right now.
Anonymous(Private) May 14, 2019 at 1:30 pm #211140I have another topic regardless this one.
For example, my search query have custom taxonomy named “product_type”.
I’m using this line to retrive what kind of “product_type” is retrived right now:
$searchProductType = $sf_current_query->get_field_string("_sft_product_type");
However, is there any option to get ID of searched taxonomy instead of “Product Type: Name” ?
Ross Moderator(Private) May 19, 2019 at 10:26 pm #211667Hi Michal
In regards to your original question, about prepending posts to the results array.
I don’t think it’s possible.
S&F uses a
WP_Query
which is the WP way of generating a query, with the results as valid post objects.There are no WP_Query params that we can use (in our
sf_edit_query_args
filters, which is basically a filter forWP_Query
args) to do this.The only way I could see you doing it, is in your results template.
You could run a query for the posts you want, and then combine it with the results from S&F.
I’m afraid achieving this specifically would be out of scope of support, but the above would be the general logic.
You also mentioned being able to do this only when a specific taxonomy is selected, and that can be done with the info from your second question:
You wanted to get the IDs of the terms.
If you use
get_array
instead ofget_field_string
you’ll see that taxonomies have IDs as well as slug and label – https://searchandfilter.com/documentation/accessing-search-data/#getan-array-offilterswithvalues-and-labels.I hope the above is clear!
Thanks
-
AuthorPosts