[wp-trac] [WordPress Trac] #35512: Inconsistent behavior when passing `post_status=any` to WP_Comment_Query

WordPress Trac noreply at wordpress.org
Thu Jan 28 04:36:59 UTC 2016


#35512: Inconsistent behavior when passing `post_status=any` to WP_Comment_Query
--------------------------------------------------+------------------
 Reporter:  danielbachhuber                       |       Owner:
     Type:  defect (bug)                          |      Status:  new
 Priority:  normal                                |   Milestone:  4.5
Component:  Comments                              |     Version:
 Severity:  normal                                |  Resolution:
 Keywords:  has-patch has-unit-tests 2nd-opinion  |     Focuses:
--------------------------------------------------+------------------
Changes (by boonebgorges):

 * keywords:  has-patch has-unit-tests => has-patch has-unit-tests 2nd-
               opinion
 * milestone:  Future Release => 4.5


Comment:

 Thanks for the patch, @kouratoras.

 Currently, omitting the 'post_type' parameter will result in post_type
 being ignored altogether. That is, when you don't specify a 'post_type',
 comments will be returned even from posts where `exclude_from_search =
 true`. (The same is true for 'post_status'.)

 I assume that you based your patch on the 'all' logic in `WP_Query`. But
 `WP_Query` has non-null defaults for 'post_status' and 'post_type'. In the
 case of 'post_status', non-singular queries fall back on 'publish' when
 'post_status' is not provided. And 'post_type' will fall back on 'post' in
 most cases https://core.trac.wordpress.org/browser/tags/4.4.1/src/wp-
 includes/query.php?marks=3080-3083#L3063

 So the semantics are somewhat different. In the case of `WP_Query`, it's
 not possible to query for `exclude_from_search` post types or statuses,
 except by explicitly whitelisting them. (eg `'post_status' => 'draft'`) So
 it makes sense that 'any' would have the same restriction. But the same
 thing cannot be said for comment queries: excluding 'post_status' will
 result in 'post_status' being ignored altogether. It feels strange that
 'any' would be more restrictive than simply omitting the param.

 Setting aside the consistency of the semantics, I'm not sure that comments
 ought to obey the exclude_from_search status of their parent posts. If a
 post has a status that excludes it from queries, then of course, you don't
 want it to appear in `WP_Query` results. But the status of a post doesn't
 really have anything to do with its comments.

 For these reasons, I'm leaning toward discarding the `exclude_from_search`
 logic in the patch. However, this is an unclear issue, so I'd be glad to
 hear what others have to say.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35512#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list