get_posts_by_author_sql example

$meta_query_clauses = $this->meta_query->get_clauses();

        $_orderby = '';
        if ( in_array( $orderby, array( 'login', 'nicename', 'email', 'url', 'registered' ), true ) ) {
            $_orderby = 'user_' . $orderby;
        } elseif ( in_array( $orderby, array( 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered' ), true ) ) {
            $_orderby = $orderby;
        } elseif ( 'name' === $orderby || 'display_name' === $orderby ) {
            $_orderby = 'display_name';
        } elseif ( 'post_count' === $orderby ) {
            // @todo Avoid the JOIN.             $where             = get_posts_by_author_sql( 'post' );
            $this->query_from .= " LEFT OUTER JOIN ( SELECT post_author, COUNT(*) as post_count FROM $wpdb->posts $where GROUP BY post_author ) p ON ({$wpdb->users}.ID = p.post_author)";
            $_orderby          = 'post_count';
        } elseif ( 'ID' === $orderby || 'id' === $orderby ) {
            $_orderby = 'ID';
        } elseif ( 'meta_value' === $orderby || $this->get( 'meta_key' ) === $orderby ) {
            $_orderby = "$wpdb->usermeta.meta_value";
        }

function count_user_posts( $userid$post_type = 'post', $public_only = false ) {
    global $wpdb;

    $where = get_posts_by_author_sql( $post_type, true, $userid$public_only );

    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where);

    /** * Filters the number of posts a user has written. * * @since 2.7.0 * @since 4.1.0 Added `$post_type` argument. * @since 4.3.1 Added `$public_only` argument. * * @param int $count The user's post count. * @param int $userid User ID. * @param string|array $post_type Single post type or array of post types to count the number of posts for. * @param bool $public_only Whether to limit counted posts to public posts. */

function get_private_posts_cap_sql( $post_type ) {
    return get_posts_by_author_sql( $post_type, false );
}

/** * Retrieves the post SQL based on capability, author, and type. * * @since 3.0.0 * @since 4.3.0 Introduced the ability to pass an array of post types to `$post_type`. * * @see get_private_posts_cap_sql() * @global wpdb $wpdb WordPress database abstraction object. * * @param string|string[] $post_type Single post type or an array of post types. * @param bool $full Optional. Returns a full WHERE statement instead of just * an 'andalso' term. Default true. * @param int $post_author Optional. Query posts having a single author ID. Default null. * @param bool $public_only Optional. Only return public posts. Skips cap checks for * $current_user. Default false. * @return string SQL WHERE code that can be added to a query. */
Home | Imprint | This part of the site doesn't use cookies.