Forums Forums Search & Filter Pro Limit filter results to within current custom taxonomy

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

    Trevor
    #74335

    Do you have a search page URL where I can see the form as you have it so far?

    Anonymous
    #74413

    Unfortunately, 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
    #74829

    It 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).

    Anonymous
    #74933

    Could you please re-read my last post?

    Your suggestion does not address my questions at all. Note that our 9-hour time difference is causing a delay of days, so please be as thorough as possible in one response.

    Many thanks.

    Trevor
    #75105
    This reply has been marked as private.
    Ross Moderator
    #75231

    Hi 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 attach search_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

    Anonymous
    #75234

    Thank you both. I am also a WordPress developer, so this is clear. I’ll give it a try and see how it goes. Much appreciated.

    Michael

    Trevor
    #75304

    Do you let us know how you get on (and maybe post any code you make that works for you so that others can see and use?). I will leave this thread open waiting for you to confirm if the issue is resolved.

Viewing 9 posts - 1 through 9 (of 9 total)