Hi there,
I'm creating a page that shows posts with different statuses on each tab of a tabs element. I would like to create one view and then filter by status using a shortcode attribute, but that option doesn't come up when I set the filter to post status. It only gives me the ability check which statuses i want rather than set them as a shortcode attribute.
Am I missing something here?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
to filter the view with the post status added as view's shortcode attribute, you will have to use the view's filter "wpv_filter_query":
For example, please try to add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
add_filter( 'wpv_filter_query', 'func_filter_shortcode_attr_with_post_status', 99, 3 );
function func_filter_shortcode_attr_with_post_status( $query_args, $view_settings, $views_id ) {
if ( $views_id == 99999) {
global $WP_Views;
$status = $WP_Views->view_shortcode_attributes[0]['post_status'];
$query_args['post_status'] = array();
if(isset($status) and $status!=''){
$query_args['post_status'][] = $status;
}
}
return $query_args;
}
Where:
- change the 99999 with your original View ID
Then you can add your view as:
[wpv-view name="your-view-slug" post_status='publish']
[wpv-view name="your-view-slug" post_status='draft']
More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query