Skip Navigation

[Resolved] Search form using Custom Post Types

This support ticket is created 5 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1190498

Hi,

Please refer to this post: https://toolset.com/forums/topic/post-type-filter/

And the comments made by Oliver, after the topic was closed.

We're having the same problem - We're using custom post type filters as checkboxes and initially the first search results are fine. If you then alter your search to use a different combination of custom post types it combines the previous searches and the new search together in the URL parameters.

Search one: (Selecting post types: post and organization)

/?wpv_view_count=10170-TCPID2274&wpv_post_search=rob&wpv-post-type[]=organization&wpv-post-type[]=post

Search Two: (unticking post and organization and checking contact and page)

/?wpv-post-type[]=organization&wpv-post-type[]=post&wpv_view_count=10170-TCPID2274&wpv_post_search=rob&wpv-post-type[]=contact&wpv-post-type[]=page

You can see that in the URL parameter the old checkboxes have been kept.

functions php code:

add_filter( 'wpv_filter_query', 'post_type_filter_func', 10, 3 );
function post_type_filter_func( $query_args, $settings, $view_id ) {
if ( $view_id == 10170 && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0]) ) {
$query_args['post_type'] = $_GET['wpv-post-type'][0];
}
return $query_args;
}

#1190554

Hi, can you tell me if it makes a difference when you use or disable AJAX to update the View?

#1190957

Hi Christian,

Thanks for the suggestion -

Selecting either of the Full page load options yields the same result.

However, Enabling either of the AJAX options fixes the issue when selecting one post type checkbox.

For example if I select post type pages then click load it will load the results fine. If we then select pages and contacts, it will only load one post type.

-- I think I have fixed this issue now by changing the functions code to $query_args['post_type'] = $_GET['wpv-post-type']; without the [0].

We'll do some more testing to confirm.

#1191628

Okay I'll stand by for your update, thanks.