Skip Navigation

[Resolved] Same function for more than a View ID for Post Type Filter

This support ticket is created 5 years, 11 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Nashaat 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#906717

Tell us what you are trying to do?

I have created a post type Filter following Minesh here: https://toolset.com/forums/topic/post-type-filter/ and this works just fine!!

the question is if its possible to add more thean VIEWS ID to the same function. i tried using Komma but this didnt work
how to achieve this?

Code that works for 1 View ID:

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

This doesn't work>

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

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nashaat,

Thank you for contacting our support forum.

The correct way to implement this can be seen below.

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

$ids= array( 2222, 3333, 4444);
    if ( in_array($view_id, $ids) && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0]) ) {
        $query_args['post_type'] = $_GET['wpv-post-type'][0];
    }
    return $query_args;
}

Thanks,
Shane

#907098

Thank you Shane! works great!

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