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...
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
Sorry i havent tried it yet... thank you in advance... will try your solution asap
Please let me know if you need more assistance, thanks