Skip Navigation

[Resuelto] Create a view from multiple posts types and filter for selecting a post type

This support ticket is created hace 7 años, 4 meses. 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 – 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)

Etiquetado: 

This topic contains 3 respuestas, has 2 mensajes.

Last updated by Luo Yang hace 7 años, 3 meses.

Assisted by: Luo Yang.

Autor
Mensajes
#474145

I've created a view that displays a grid form multiple post types.

e.g.
post type one
post type two
post type three
etc.

I would like to add a filter that makes it possible for the user to select a post type ... so then the grid only shows the selected post types... is that possible ?

I can't find a filterable element that makes it possible to filter on the post types...

#474351

Dear herre,

There isn't such a built-in feature within Views plugin, I suggest you try this:
1) Edit your view, in section "Filter Editor", add a dropdown menu for user filter by post type, for example:

[wpv-control  url_param="my-post-type" type="select" values=",page,post" display_values="All,Pages,Posts"]

You can add more post types into above dropdwon menu

2) Add below codes in your theme/functions.php:

add_filter( 'wpv_filter_query', 'filer_by_post_type_func', 10, 3 );
function filer_by_post_type_func( $query_args, $settings, $view_id ) {
    if($view_id != 123) return $query_args;
    if ( isset($_GET['my-post-type'][0]) && $_GET['my-post-type'][0] != '') {
        $query_args['post_type'] = $_GET['my-post-type'][0];
    }
    return $query_args;
}
add_filter('wpv_filter_wpv_get_pagination_permalinks', 'my_url_func', 30, 3);
function my_url_func($arr, $view_settings, $view_id ){
    if($view_id != 123) return $arr;
    $query_args_remove = array();
    $query_args_remove[]    = 'my-post-type';
    $arr['first'] = remove_query_arg(
            $query_args_remove,
            $arr['first']
        );
    return $arr;
}

Please replace 123 with your view's ID

#475647

Sorry i havent tried it yet... thank you in advance... will try your solution asap

#476198

Please let me know if you need more assistance, thanks

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