Including taxonomies

Forums › Forums › Search & Filter Pro › Including taxonomies

Viewing 3 posts – 1 through 3 (of 3 total)
  • Anonymous
    #207479

    Hi Trevor,
    I have a page that is displaying a post grid in which only 2 specific taxonomy values are included:
    1. library_author: “OM Australia”
    2. library_country: “Australia”
    https://2019.om.org.au/library/australian
    The idea is that this page displays all posts written by “OM Australia” OR tagged as “Australia” (om_country tax).
    I have created a Search and Filter form for this page, but when I “Include” their IDs under the “Tags, Categories & Taxonomies” tab, the page only displays posts written by “OM Australia” AND tagged with “Australia”. It needs to be OR.
    When I remove the IDs from under the “Tags, Categories & Taxonomies” tab, the page displays correctly (all posts by “OM Australia” or tagged “Australia”) but the filter options are displaying ALL the taxonomies (not just the ones assigned to the posts on the page).
    Any ideas how I can get this to work?
    Hope this makes sense.
    Thanks
    Ian

    Trevor
    #207496

    What you want cannot be done in the form UI settings, as the Includes are always set as AND. You might need to do this using this filter instead:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Anonymous
    #207594

    Thanks Trevor.

    I managed to get it working with this:

    function filter_aus_library ( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==14334)
    	{
    		//modify $query_args here before returning it
    		$query_args['tax_query'] = array(
      'relation' => 'OR', 
      array(
        'taxonomy' => 'library_country',
        'terms'    => '1497',
      ),
    	array(
        'taxonomy' => 'library_author',
        'terms'    => '2192',
      )
    );
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_aus_library', 20, 2 );
Viewing 3 posts – 1 through 3 (of 3 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.