Forums › Forums › Search & Filter Pro › Including taxonomies
- This topic has 2 replies, 2 voices, and was last updated 5 years, 7 months ago by Anonymous.
-
Anonymous(Private) April 4, 2019 at 7:53 am #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
IanTrevor(Private) April 4, 2019 at 11:50 am #207496What 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(Private) April 4, 2019 at 11:50 pm #207594Thanks 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 );
-
AuthorPosts