Skip Navigation

[Resolved] Parametric search to filter a view by post status

This support ticket is created 6 years, 1 month 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
- 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 2 replies, has 2 voices.

Last updated by stewartE 6 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1122776

Hi I was wondering if it is possible to use parametric search to filter a view by post status.

So...

I create a view that shows posts that are Published, Draft and Pending. The user can then use a filter on the front end to filter down the list to for example show only Draft Posts.

Thanks!

#1123471

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - By default, there is no native filter available to add the filter for post status. But you can work around a bit by following the next steps.

1)
Edit your view and add the following code at "Search and Pagination" section.

[wpml-string context="wpv-views"]Post Status:[/wpml-string] 
[wpv-control field="wpv-post-status" url_param="wpv-post-status" type="select" values="any,publish,draft" display_values="Any,Publish,Draft"]

[wpv-filter-submit output="bootstrap"]

Where:
- You can adjust your number of post status with "values" and "display_values" attributes. Feel free to adjust yourselt.

2)
Edit your current theme's functions.php file and add the following code. To filter the posts by post status we need to use view's filter wpv_filter_query :

add_filter( 'wpv_filter_query', 'filter_post_type_status_func', 10, 3 );
 
function filter_post_type_status_func( $query_args, $view_settings, $view_id ) {
    if ( $view_id == 9999 ) {
        if(isset($_GET['wpv-post-status'])){
            $query_args['post_status'] = $_GET['wpv-post-status'];
        }
    }
    return $query_args;
}

Where:
- Replace 9999 with your original view ID

More info:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

#1127365

My issue is resolved now. Thank you!