Modify results query if specific taxonomy is selected

Forums › Forums › Search & Filter Pro › Modify results query if specific taxonomy is selected

Viewing 4 posts – 1 through 4 (of 4 total)
  • Anonymous
    #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.

    Trevor
    #211130

    You are correct, but I am not sure how you would do this. I will refer this to the plugin developer, Ross, for his input.

    Anonymous
    #211140

    I 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
    #211667

    Hi 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 for WP_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 of get_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

Viewing 4 posts – 1 through 4 (of 4 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.