Skip Navigation

[Resolved] Creating a View to Display Posts that are Pending Review

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to include posts with a status of "Pending review" in the output of a View.

Solution:
By default a View will only list published or private posts. To include other statuses it is necessary to use the wpv_filter_query API filter to modify the query arguments.

An example of such code would be:

function ts_filter_query( $view_args, $view_settings, $view_id )  {
   
  if ( in_array( $view_id, array( 117 ) ) ) { // list of View IDs to apply this to
     
    $view_args['post_status'] = array( 'publish', 'pending' );
  }
   
  return $view_args;
}
add_filter( 'wpv_filter_query', 'ts_filter_query', 101, 3 );

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 4 years, 7 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by andrei-laurentiuP 4 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1312901

Tell us what you are trying to do?

I have a view that lists all posts by user. All new posts are set to Pending Review. I would like to list the Pending Review Posts to the user as well, not only what has been published. Is there any way to do that?

Regards,
Andrei

#1312955

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The UI doesn't offer the ability to specify the post statuses that Views should include in its queries, which are always "publish" or "private".

To modify that you need to use the wpv_filter_query filter to update the query arguments yourself.

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

The code you need would be something like:

function ts_filter_query( $view_args, $view_settings, $view_id )  {
  
  if ( in_array( $view_id, array( 117 ) ) ) { // list of View IDs to apply this to
    
    $view_args['post_status'] = array( 'publish', 'pending' );
  }
  
  return $view_args;
}
add_filter( 'wpv_filter_query', 'ts_filter_query', 101, 3 );

You'll need to edit the View ID(s).

#1312957

Thank you very much, Nigel! That works perfectly! My issue is resolved now. Thank you!

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