Make WordPress Core

Opened 13 years ago

Last modified 6 years ago

#20597 new enhancement

Allow WP_Comment_Query::query to filter by category

Reported by: sambauers's profile sambauers Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Comments Keywords: needs-patch needs-unit-tests
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 13 years ago.

Download all attachments as: .zip

Change History (5)

#1 @sambauers
13 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.

#2 @helenyhou
13 years ago

  • Description modified (diff)

#3 @boonebgorges
10 years 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.

#4 @chriscct7
9 years ago

  • Keywords needs-unit-tests added
Note: See TracTickets for help on using tickets.