Skip Navigation

[Resolved] Searching two different post types on separate pages

This thread is resolved. Here is a description of the problem and solution.

Problem:
Searching two different post types on separate pages using one view
Solution:
You can use the Toolset block/view's filter hook "wpv_filter_query" to change post type on fly.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/searching-two-different-post-types-on-separate-pages/#post-1873007

Relevant Documentation:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 3 years, 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by digitalF 3 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1872019

Hi we have a website which has both the toolset blocks and views, with a search page enabled.

Currently what we're trying to do is have two separate search pages, each returning a different post type. For simplicity I'll call them post type A and post type B.

I've copied the search forms views into the two separate pages, however when I choose to filter the search results by a certain post type, this affects both pages.

Is there any way to have two separate pages with a search form on each returning results for 'post type A' on one page and 'post type B' on another?

Any queries please let me know.

Thanks,

Nathan

#1872931

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

It seems you have set your view to query two post types (A and B). And then you have a search form and you want to filter your post by post type and also want to display that on different search result page.
- Please correct me if I misunderstood your issue.

Normally, with the custom search view, you can have only one search result page but lets see and analyse your requirement first.

I would like to first see how exactly you setup your view and configured the search result page. Also, if you can share a test case that should explain what you want to display with different search result page that would help me to guide you in the right direction.

For that, I will require link of the page where you added your search form as well as where you configured the search results page and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1873007

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've added the View's filter hook wpv_filter_query to "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_query', 'post_type_filter_func', 10, 3 );
function post_type_filter_func( $query_args, $settings, $view_id ) {

  $page_id = get_queried_object_id();
  
  $view_ids_array = array(275);
  
  	if ( in_array($view_id, $view_ids_array)  and $page_id==271) {
        $query_args['post_type'] = 'competition';
    }
    
    return $query_args;
}

Can you please confirm it works as expected?

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#1873101

This is sport on! Exactly what we needed, thank you very much indeed for your help.

Much appreciated. 🙂

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