I am trying to: load a filtered view based on more than one attribute
Link to a page where the issue can be seen: hidden link
I expected to see: only posts matching the filter
Instead, I got: all posts even those not matching the filter
Please see this video https : // jumpshare . com /v/LmGrGbFmJymz2FCtHyA9 for information
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
It seems you want to apply "AND" clause between the checkboxes option you select for "Topics" taxonomy.
=> hidden link
I've added the following filter code to "Custom Code" section offered by Toolset:
add_filter( 'wpv_filter_query', 'func_filter_by_taxonomy_terms_and_clause', 10, 3 );
function func_filter_by_taxonomy_terms_and_clause( $query, $view_settings, $views_id ) {
if ( $views_id == 2019 ) {
if(isset($_GET['wpv-post_tag']) and !empty($_GET['wpv-post_tag']) ){
$tax_array = array('relation'=>'AND');
foreach($_GET['wpv-post_tag'] as $k=>$v):
$tax_query_array[] = array('taxonomy'=>'post_tag','field'=>'slug','terms'=>$v,'operator'=>'IN');
endforeach;
unset($query['tax_query']);
$query['tax_query'] = array($tax_query_array);
}
}
return $query;
}
Could you please check now if it works as expected:
- hidden link
Yes it is functioning like it should be now! Thanks!
But it looks like the layout on that view is now broken hidden link and overlapping the content box that it is inside of?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I do not experience the same, I tried to filter the view with terms "Activism" and "HBCU" I can see it filters the result correctly.
Please check the following screenshot:
- hidden link
Do you still experience the issue?