get_private_posts_cap_sql

Retrieve the private post SQL based on capability.

Description

(string) get_private_posts_cap_sql( (string|array) $post_type ); 

This function provides a standardized way to appropriately select on the post_status of a post type. The function will return a piece of SQL code that can be added to a WHERE clause; this SQL is constructed to allow all published posts, and all private posts to which the user has access.

Returns (string)

SQL code that can be added to a where clause.

Parameters (1)

0. $post_type (string|array)
Single post type or an array of post types. Currently only supports post or page..

Usage

  1. if ( !function_exists( 'get_private_posts_cap_sql' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Single post type or an array of post types. Currently only supports 'post' or 'page'. 
  5. $post_type = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_private_posts_cap_sql($post_type); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function get_private_posts_cap_sql( $post_type ) { 
  2. return get_posts_by_author_sql( $post_type, false );