WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#21003 closed enhancement (fixed)

WP_Comment_Query with WP_Meta_Query integration

Reported by: nikolov.tmw Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4
Component: Comments Keywords: has-patch needs-testing
Focuses: Cc:

Description

Basically the title says it all. What I'd like to see in WordPress is an implementation of the WP_Meta_Query that was intorduced in 3.2 for the comments query as well as ordering by meta values.

Basically if those features are implemented, developers will have greater flexibility about comments - the first things that come to mind are rating system(I know there should be a plugin out there for that already), separating comments by some parameter(let's say age/sex/country/etc, if there is some kind of sociological study) and many more.

I stumbled upon this quite recently when I was making an extension for qTranslata and I had to get comments by specific meta value - I had to either write custom MySQL(at which I'm not really good), or implement the meta query.

I'm attaching the diff file that I made(I've tested that with 3.4) for wp-includes/comments.php

Attachments (5)

comment.php.patch (3.0 KB) - added by nikolov.tmw 4 years ago.
Patch for integrating meta_query and meta_value ordering for comments queries
21003.diff (3.3 KB) - added by ryan 4 years ago.
Refresh
21003-ut.diff (2.0 KB) - added by ryan 4 years ago.
21003.2.diff (3.9 KB) - added by ryan 4 years ago.
Quick group by patch
21003.reinstate-cache.diff (550 bytes) - added by duck_ 4 years ago.

Download all attachments as: .zip

Change History (17)

@nikolov.tmw
4 years ago

Patch for integrating meta_query and meta_value ordering for comments queries

#1 @scribu
4 years ago

Looks good on first glance.

#2 @scribu
4 years ago

  • Milestone changed from Awaiting Review to 3.5

#3 @Mamaduka
4 years ago

  • Cc georgemamadashvili@… added

#4 @nacin
4 years ago

  • Keywords commit added; 2nd-opinion removed

Needs a final review.

@ryan
4 years ago

Refresh

@ryan
4 years ago

#7 @ryan
4 years ago

The last assertion in those tests fails. The same comment occurs twice in the results.

#8 @scribu
4 years ago

  • Keywords commit removed

In WP_Query, we have this for dealing with duplicates:

if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
	$groupby = "{$wpdb->posts}.ID";
}

@ryan
4 years ago

Quick group by patch

#9 follow-up: @ryan
4 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [22074]:

Support meta queries in WP_Comment_Query.

Props nikolov.tmw
fixes #21003

#10 in reply to: ↑ 9 @duck_
4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to ryan:

In [22074]:

Support meta queries in WP_Comment_Query.

Props nikolov.tmw
fixes #21003

return $cache was left commented out on line 260.

Edit: also still says @since 3.?

Last edited 4 years ago by duck_ (previous) (diff)

#11 @ryan
4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In [22079]:

Remove debug cruft. Props duck_. fixes #21003

Note: See TracTickets for help on using tickets.