Make WordPress Core

Changeset 4180


Ignore:
Timestamp:
09/10/2006 05:47:49 PM (20 years ago)
Author:
ryan
Message:

Get pages by author[s]. Props westi. fixes #1486

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r4165 r4180  
    266266
    267267        $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'),
    268                 'child_of' => 0, 'title_li' => __('Pages'), 'echo' => 1);
     268                'child_of' => 0, 'title_li' => __('Pages'), 'echo' => 1, 'authors' => '');
    269269        $r = array_merge($defaults, $r);
    270270
  • trunk/wp-includes/post.php

    r4159 r4180  
    10381038
    10391039        $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title',
    1040                                 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '');
     1040                                'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '');
    10411041        $r = array_merge($defaults, $r);
    10421042        extract($r);
    … …  
    10761076                $exclusions .= ')';
    10771077
     1078        $author_query = '';
     1079        if (!empty($authors)) {
     1080                $post_authors = preg_split('/[\s,]+/',$authors);
     1081               
     1082                if ( count($post_authors) ) {
     1083                        foreach ( $post_authors as $post_author ) {
     1084                                //Do we have an author id or an author login?
     1085                                if ( 0 == intval($post_author) ) {
     1086                                        $post_author = get_userdatabylogin($post_author);
     1087                                        if ( empty($post_author) )
     1088                                                continue;
     1089                                        if ( empty($post_author->ID) )
     1090                                                continue;
     1091                                        $post_author = $post_author->ID;
     1092                                }
     1093
     1094                                if ( '' == $author_query )
     1095                                        $author_query = ' post_author = ' . intval($post_author) . ' ';
     1096                                else
     1097                                        $author_query .= ' OR post_author = ' . intval($post_author) . ' ';
     1098                        }
     1099                        if ( '' != $author_query )
     1100                                $author_query = " AND ($author_query)";
     1101                }
     1102        }
     1103
    10781104        $query = "SELECT * FROM $wpdb->posts " ;
    10791105        $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ;
    10801106        $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ;
    10811107        $query .= ( empty( $meta_key ) | empty($meta_value)  ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ;
     1108        $query .= $author_query;
    10821109        $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
    10831110
Note: See TracChangeset for help on using the changeset viewer.