I am trying to:
Filter results for specific post types in search results and archive pages.
Link to a page where the issue can be seen:
It works here=> hidden link
--- click on master articles under filter by type and all of the results will be blue with a star in the top right corner
But not here=>
hidden link
--- click on master articles under filter by type and the results change, but displays other post types
After search through support, I was able to find this solution:
////////////////////////////////////////////////////////////////////////
// Toolset Filter by Post Type /////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
add_filter( 'wpv_filter_query', 'post_type_filter_func', 10, 3 );
function post_type_filter_func( $query_args, $settings, $view_id ) {
// add comma separated view ids
$view_ids_array = array(52121,15526,52169);
if ( in_array($view_id, $view_ids_array) && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0]) ) {
$query_args['post_type'] = $_GET['wpv-post-type'][0];
}
return $query_args;
}
However, I'm using the wordpress archives ids (15526,52169) instead of views IDs.
How would I get this to work across views and wordpress archives?
Hello,
I assume the URL you mentioned above is a term's archive page:
hidden link
The filter hook "wpv_filter_query" only takes effect on normal view, it will not take effect on the wordpress archives.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
In your case, you can try with wordpress built-in filter hook to apply custom filters:
https://codex.wordpress.org/Plugin_API/Action_Reference/parse_query