Skip Navigation

[Resolved] Post type filter not working on search or wordpress archive pages

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#631486

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?

#631793

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

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.