Make WordPress Core


Ignore:
Timestamp:
01/22/2016 08:19:49 PM (9 years ago)
Author:
boonebgorges
Message:

Allow comment query results to be limited to comments with comment_post_ID = 0.

Previously, this was not possible due to an overly broad empty() check.

Passing null, false, or '' to 'post_id', or omitting 'post_id'
altogether, will continue to return comments regardless of comment_post_ID,
as before. Passing 0 or '0' will limit results to comments with no
associated post.

Props danielbachhuber.
Fixes #35090.

File:
1 edited

Legend:

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

    r36345 r36381  
    215215     *     @type int          $post_ID                   Currently unused.
    216216     *     @type int          $post_id                   Limit results to those affiliated with a given post ID.
    217      *                                                   Default 0.
     217     *                                                   Default null.
    218218     *     @type array        $post__in                  Array of post IDs to include affiliated comments for.
    219219     *                                                   Default empty.
     
    277277            'post_author__not_in' => '',
    278278            'post_ID' => '',
    279             'post_id' => 0,
     279            'post_id' => null,
    280280            'post__in' => '',
    281281            'post__not_in' => '',
     
    646646        }
    647647
    648         $post_id = absint( $this->query_vars['post_id'] );
    649         if ( ! empty( $post_id ) ) {
    650             $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
     648        if ( strlen( $this->query_vars['post_id'] ) ) {
     649            $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $this->query_vars['post_id'] );
    651650        }
    652651
Note: See TracChangeset for help on using the changeset viewer.