Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_posts_by_author_sql [ WordPress Function ]

get_posts_by_author_sql ( $post_type, $full = true, $post_author = null )
Parameters:
  • (string) $post_type Post type.
  • (bool) $full Optional. Returns a full WHERE statement instead of just an 'andalso' term.
  • (int) $post_author Optional. Query posts having a single author ID.
See:
Returns:
  • (string) SQL WHERE code that can be added to a query.
Defined at:



Retrieve the post SQL based on capability, author, and type.

Source


<?php
function get_posts_by_author_sql$post_type$full true$post_author null ) {
    global 
$user_ID$wpdb;

    
// Private posts
    
$post_type_obj get_post_type_object$post_type );
    if ( ! 
$post_type_obj )
        return 
$full 'WHERE 1 = 0' ' 1 = 0 ';

    
// This hook is deprecated. Why you'd want to use it, I dunno.
    
if ( ! $cap apply_filters'pub_priv_sql_capability''' ) )
        
$cap $post_type_obj->cap->read_private_posts;

    if ( 
$full ) {
        if ( 
null === $post_author ) {
            
$sql $wpdb->prepare'WHERE post_type = %s AND '$post_type );
        } else {
            
$sql $wpdb->prepare'WHERE post_author = %d AND post_type = %s AND '$post_author$post_type );
        }
    } else {
        
$sql '';
    }

    
$sql .= "(post_status = 'publish'";

    if ( 
current_user_can$cap ) ) {
        
// Does the user have the capability to view private posts? Guess so.
        
$sql .= " OR post_status = 'private'";
    } elseif ( 
is_user_logged_in() ) {
        
// Users can view their own private posts.
        
$id = (int) $user_ID;
        if ( 
null === $post_author || ! $full ) {
            
$sql .= " OR post_status = 'private' AND post_author = $id";
        } elseif ( 
$id == (int) $post_author ) {
            
$sql .= " OR post_status = 'private'";
        } 
// else none
    
// else none

    
$sql .= ')';

    return 
$sql;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics