WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 10 months ago

#20597 new enhancement

Allow WP_Comment_Query::query to filter by category

Reported by: sambauers Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.4
Component: Comments Keywords: needs-patch
Focuses: Cc:

Description (last modified by helenyhou)

The attached patch allows WP_Comment_Query::query to accept three additional arguments:

  • cat
  • category__in
  • category__not_in

The resulting comments are then filtered by these category arguments as well as any other arguments.

These arguments work the same way as their WP_Query counterparts.

I would appreciate advice on the appropriateness of using INNER JOIN (as I have done here) to join in the taxonomy tables to the query.

Attachments (1)

comment-query-by-category.patch (2.8 KB) - added by sambauers 3 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 @sambauers3 years ago

The argument list got a bit munged there. The last two arguments should have double underscores after "category". Here is the relevant link in the codex to how WP_Query works with these arguments:

http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

That is the argument usage I have followed for this patch.

comment:2 @helenyhou3 years ago

  • Description modified (diff)

comment:3 @boonebgorges10 months ago

  • Keywords needs-patch added; has-patch needs-testing removed
  • Milestone changed from Awaiting Review to Future Release

Thanks for the patch, sambauers.

Adding these table joins into WP_Comment_Query is pretty unappealing. In WP_Query, all (or at least most) of the category query logic has been moved to WP_Tax_Query. So, if we were going to add something like this, we'd want to do it with WP_Tax_Query instead of by building the SQL like this. I guess the relevant argument for WP_Comment_Query would then be something like 'post_tax_query', since we would want to leave the door open for putting taxonomy on comments at some point in the future.

Note: See TracTickets for help on using tickets.