Forums › Forums › Search & Filter Pro › Limit filter results to within current custom taxonomy
Tagged: multiple custom taxonomies
- This topic has 8 replies, 3 voices, and was last updated 7 years, 11 months ago by Trevor.
-
Anonymous(Private) December 5, 2016 at 8:54 pm #74224
I have a custom template showing results for a custom taxonomy (category). I want to use this plugin to filter that taxonomy’s results further by another custom taxonomy (region).
Right now the region filter is showing the number (in parentheses) for all items with that region, as opposed to just the ones for the current category.
Hope this makes sense. Can you explain how to do this? Thanks.
Anonymous(Private) December 6, 2016 at 6:43 pm #74413Unfortunately, the best I can do is show you a screenshot:
http://screencast.com/t/QceoQRVQFXq9
There’s almost nothing to it, just a dropdown for the Region custom taxonomy. This is a custom taxonomy template for another custom taxonomy, which is basically a category (Food and Beverage). So, on any given results page for one of these categories, I want to be able to further filter by region.
The problems are:
1) I’m not really sure how to get this to return results in the same template with the current region filter shown as selected. It is a custom taxonomy template, not an archive.
2) The counts that are visible in the dropdown are not what I would expect. It’s showing the number of items in the queried taxonomy (Food and Beverage here), but not filtered by region.
Hope this makes more sense now. Thanks.
Trevor(Private) December 7, 2016 at 10:44 am #74829It appears from that screenshot that you have a category (which is just a fancy way of saying taxonomy) with multiple parent/child hierarchies. You should not do it this way. Instead you need to split the terms into at least two taxonomies, say area (e.g. East Bay) and region (e.g. Alameda) or whatever name for the taxonomies that makes most sense.
You can use a plugin called Custom Post Types UI to add these custom Taxonomies, and another plugin called Taxonomy Switcher to move the terms (but be careful about making terms not children of …, but parents in their own right).
Ross Moderator(Private) December 8, 2016 at 8:38 pm #75231Hi Michael
Yup Trevor is correct.
So for the first question 1)
S&F works great with post type archives (you can see this as a display method in
display results
) but it does not yet fully support taxonomy archives (hence no option).So, when you submit a search, you will find that S&F redirects to a search results page, as opposed to searching within the current taxonomy archive.
There is 1 workaround which you can do to achieve something similar but you have to do 2 things (and to be honest, you need some coding skills):
a) tell S&F to affect/modify the queries on your taxonomy archives
To do this you need to modify your taxonomy archive query, and attachsearch_filter_id
to the query (this tells S&F it is allowed to change these queries according to filtering selections)… so you will need to use the WP filter pre_get_posts.. something like:function add_sf_taxonomy_archive( $query ) { if ( $query->is_tax("taxonomy_name") && $query->is_main_query() ) { $query->set( 'search_filter_id', '1234' ); } } add_action( 'pre_get_posts', 'add_sf_taxonomy_archive');
(replace taxonomy_name with your taxonomy slug, and 1234 with your search form ID)
b) tell S&F which page it should display the results on rather than the default search result page (so, your tax term archive), as
Trevor mentioned you need use our filter to dynamically change this:function update_sf_url( $url, $sfid) { // Process URL here $termname = "termname"; //this needs to by dynamic based on current term //this url structure may not be correct for your setup but it will be something similar return home_url("/taxonomyname/".$termname ); } add_filter( 'sf_results_url', 'update_sf_url', 10, 2 ); add_filter( 'sf_ajax_results_url', 'update_sf_url', 10, 2 );
The url that is returned needs to point to the current taxonomy term URL, what I wrote above is psuedocode really…
I would also recommend to test the above with Ajax disabled for now, if that works then enable and carry on…
I hope that makes sense, if you are not a programmer though, I would say the above is very very difficult to achieve…
Best
-
AuthorPosts