Make WordPress Core

Ticket #32243: post.diff

File post.diff, 2.1 KB (added by nikonratm, 11 years ago)

Updated get_posts_by_author_sql to accept multiple post types

  • post.php

     
    53305330 *
    53315331 * @see get_private_posts_cap_sql()
    53325332 *
    5333  * @param string $post_type   Post type.
     5333 * @param array  $post_types  Post type(s).
    53345334 * @param bool   $full        Optional. Returns a full WHERE statement instead of just
    53355335 *                            an 'andalso' term. Default true.
    53365336 * @param int    $post_author Optional. Query posts having a single author ID. Default null.
     
    53385338 *                            $current_user.  Default false.
    53395339 * @return string SQL WHERE code that can be added to a query.
    53405340 */
    5341 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
     5341function get_posts_by_author_sql( $post_types, $full = true, $post_author = null, $public_only = false ) {
    53425342        global $wpdb;
    53435343
    53445344        // Private posts.
    5345         $post_type_obj = get_post_type_object( $post_type );
     5345        foreach ($post_types as $post_type) $post_type_obj = get_post_type_object( $post_type );
    53465346        if ( ! $post_type_obj )
    53475347                return $full ? 'WHERE 1 = 0' : ' 1 = 0 ';
    53485348
     
    53585358        if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) {
    53595359                $cap = $post_type_obj->cap->read_private_posts;
    53605360        }
     5361       
     5362        $post_type_sql = array_fill(0, count($post_types), '%s');
     5363        $where = '(post_type = '.implode(' OR post_type = ', $post_type_sql).')';
     5364        $sql = $wpdb->prepare($where, $post_types);
    53615365
    5362         $sql = $wpdb->prepare( 'post_type = %s', $post_type );
    5363 
    53645366        if ( null !== $post_author ) {
    53655367                $sql .= $wpdb->prepare( ' AND post_author = %d', $post_author );
    53665368        }
     
    53695371        $post_status_sql = "post_status = 'publish'";
    53705372        if ( false === $public_only ) {
    53715373                if ( current_user_can( $cap ) ) {
    5372                         // Does the user have the capability to view private posts? Guess so.
     5374                        // Does the user have the capability to view private posts (we're only checking for the last post_type, but that's ok)? Guess so.
    53735375                        $post_status_sql .= " OR post_status = 'private'";
    53745376                } elseif ( is_user_logged_in() ) {
    53755377                        // Users can view their own private posts.