Make WordPress Core

Changeset 36403


Ignore:
Timestamp:
01/26/2016 02:55:15 AM (11 years ago)
Author:
boonebgorges
Message:

Introduce $comment_status and $ping_status params for WP_Query.

Props birgire.
Fixes #35601.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r36307 r36403  
    14851485         *              search terms, by prepending a hyphen.
    14861486         * @since 4.5.0 Removed the `$comments_popup` parameter.
     1487         *              Introduced the `$comment_status` and `$ping_status` parameters.
    14871488         * @access public
    14881489         *
     
    15011502         *     @type array        $category__not_in        An array of category IDs (NOT in).
    15021503         *     @type string       $category_name           Use category slug (not name, this or any children).
     1504         *     @type string       $comment_status          Comment status.
    15031505         *     @type int          $comments_per_page       The number of comments to return per page.
    15041506         *                                                 Default 'comments_per_page' option.
     
    15461548         *     @type string       $pagename                Page slug.
    15471549         *     @type string       $perm                    Show posts if user has the appropriate capability.
     1550         *     @type string       $ping_status             Ping status.
    15481551         *     @type array        $post__in                An array of post IDs to retrieve, sticky posts will be included
    15491552         *     @type string       $post_mime_type          The mime type of the post. Used for 'attachment' post_type.
     
    30373040                }
    30383041
     3042                if ( ! empty( $q['comment_status'] ) ) {
     3043                        $where .= $wpdb->prepare( " AND $wpdb->posts.comment_status = %s ", $q['comment_status'] );
     3044                }
     3045
     3046                if ( ! empty( $q['ping_status'] ) )  {
     3047                        $where .= $wpdb->prepare( " AND $wpdb->posts.ping_status = %s ", $q['ping_status'] );
     3048                }
     3049
    30393050                if ( 'any' == $post_type ) {
    30403051                        $in_search_post_types = get_post_types( array('exclude_from_search' => false) );
  • trunk/tests/phpunit/tests/query.php

    r35242 r36403  
    493493                $this->assertContains( 'LIMIT 5, 5', $q->request );
    494494        }
     495
     496        /**
     497         * @ticket 35601
     498         */
     499        public function test_comment_status() {
     500                $p1 = self::factory()->post->create( array( 'comment_status' => 'open' ) );
     501                $p2 = self::factory()->post->create( array( 'comment_status' => 'closed' ) );
     502
     503                $q = new WP_Query( array(
     504                        'fields' => 'ids',
     505                        'comment_status' => 'closed',
     506                ) );
     507
     508                $this->assertSame( array( $p2 ), $q->posts );
     509        }
     510
     511        /**
     512         * @ticket 35601
     513         */
     514        public function test_ping_status() {
     515                $p1 = self::factory()->post->create( array( 'ping_status' => 'open' ) );
     516                $p2 = self::factory()->post->create( array( 'ping_status' => 'closed' ) );
     517
     518                $q = new WP_Query( array(
     519                        'fields' => 'ids',
     520                        'ping_status' => 'closed',
     521                ) );
     522
     523                $this->assertSame( array( $p2 ), $q->posts );
     524        }
    495525}
Note: See TracChangeset for help on using the changeset viewer.