Skip Navigation

[Resolved] Filter view by post status

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

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: Africa/Casablanca (GMT+01:00)

This topic contains 15 replies, has 2 voices.

Last updated by Jamal 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1910561

another point is to to add Post status into search filed so that once can search post based on Post Status.

#1910585

Hello and thank you for contacting the Toolset support.

There is no built-in filter for the post status in the view's filters. You need to add it manually and alter the query filters programmatically with custom code. Check this reply from my colleague Luo on another ticket https://toolset.com/forums/topic/post-status-filter-select/#post-306570

I hope this helps. Let me know if you have any questions.

#1912133

My issue is resolved now. Thank you!

#1912135

What I couldn't understand it is

Yes, it is possible with Views filter hook "wpv_filter_query", for example,
1) edit your view, in section "Filter", add a dropdown menu for post status, like this:

where I can found the section "Filter" as still unable to find that . Can you help me.

#1913393

Still waiting for your kind response.

#1914301

Hello and my apologies for the late reply, but I do not work on Wednesdays and Thursdays.

If you are building the view with the legacy editor, make sure that the search is activated in the screen options. Check this screenshot hidden link
Then add the dropdown, using HTML, as there is no built-in filter for post types, in the Search and Pagination section. My apologies for the confusion. hidden link

If you are building the view with Blocks, make sure to activate the search for the view and use an HTML block to build the dropdown. Check this screenshot hidden link

#1915765

Thank, I have created it but still unable to filter Post based on Post Staus. Can you help me out furhter.

#1915787

Maybe you did not add the custom code to modify the view's query arguments!

Of course, I'll do my best to help. Let me access your site's backend and check what has been done so far. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1916605

The view is built using blocks and it presents an issue with the view's shortcode. I replaced the shortcode with HTML code and it displays all the statuses. hidden link

<select id="wpv_control_select_my-post-status" name="my-post-status[]" style="" class="js-wpv-filter-trigger  wpcf-form-select form-select select">
  <option value="any" class="js-wpv-filter-trigger  wpcf-form-option form-option option">Any</option>
  <option value="publish" class="js-wpv-filter-trigger  wpcf-form-option form-option option">Publish</option>
  <option value="pending" class="js-wpv-filter-trigger  wpcf-form-option form-option option">Pending</option>
  <option value="draft" class="js-wpv-filter-trigger  wpcf-form-option form-option option">Draft</option>
  <option value="trash" class="js-wpv-filter-trigger  wpcf-form-option form-option option">Trash</option>
  <option value="future" class="js-wpv-filter-trigger  wpcf-form-option form-option option">Future</option>
</select>

However, the search is performed using AJAX, which means that performs POST requests instead of GET request. Check this hidden link
The code needs to be adapted to check for POST parameters instead of GET parameters. If you would allow me a copy of your website I'll debug the code locally and get it to you. Sounds good?

#1917249

ok do proceed would request only for sellit ..

#1917251

and just to let know that next step is to creat front end editing with the option to change post status so there I need your guidence as well

#1917441

The custom code checks against a wrong ID, 492 is the ID of the page. The ID of the view is 493. Change the code to the following and it will work:

add_filter( 'wpv_filter_query', 'my_posts_by_status', 10, 3 );
function my_posts_by_status ( $query_args, $view_settings, $view_id ) {
  if( $view_id == 493 ) {
	if(isset($_GET['my-post-status'])){
		$query_args['post_status'] = $_GET['my-post-status'];
	} else {
		$query_args['post_status'] = array('any');
	}
  }
  return $query_args;
}

I tried this on my local install because I needed Duplicator Pro to copy a subsite in a multisite Install.

Let's work on the other request on a new ticket.

#1917501
toolset.JPG

Hi Jamal,

It is working now but due to some reason as I open up the page I received following page as popup, it i strange to me why?
But only for login user and I am using firefox.
Previusly it was not like that..

I have updated the code as below:

in case need new more forms.
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 ( in_array($view_id, array(493)) ) {
if(isset($_GET['my-post-status'])){
$query_args['post_status'] = $_GET['my-post-status'];
}
}
return $query_args;
}

#1917581

That's the View's debug popup. I must have left it activated in Toolset->Settings->Front-end Content(tab). Read more about it here https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#the-views-debug-tool

#1917761

Ah ok good to know I guess that is just for backend debug but once again great tool.

Now I have created a Front end Form for editing as well only thing is to make changes to post satus via Post Editing front end from would be great if you can see it today and help me out further as well. Then I don't have to explain it to any one else.

New threads created by Jamal and linked to this one are listed below:

https://toolset.com/forums/topic/change-post-status-using-a-form/