Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#28434 closed enhancement (fixed)

Add 'fields' parameter to WP_Comment_Query

Reported by: mordauk's profile mordauk Owned by: nacin's profile nacin
Milestone: 4.0 Priority: normal
Severity: normal Version: 4.0
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

The WP_Comment_Query class should support a fields argument, just like WP_Query does.

Attachments (3)

28434.patch (788 bytes) - added by mordauk 11 years ago.
Adds support for 'fields' parameter
28434-tests.patch (1.1 KB) - added by mordauk 11 years ago.
28434.diff (2.7 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (15)

@mordauk
11 years ago

Adds support for 'fields' parameter

#1 @DrewAPicture
11 years ago

  • Keywords needs-unit-tests added

+1

I'm surprised this has never been suggested before (at least, my searching yielded nothing).

#2 @mordauk
11 years ago

  • Keywords has-patch added; needs-unit-tests removed

Basic unit tests added.

#3 @SergeyBiryukov
11 years ago

  • Milestone changed from Awaiting Review to 4.0

#5 @wonderboymusic
11 years ago

28434.diff is more in line with how get_posts() works. Not sure that id=>parent should be comment_ID=>comment_post_ID. Seems like comment_parent might be more appropriate. Updated the unit tests as well, which didn't pass and didn't contain all new values for fields.

#7 @nacin
11 years ago

Because id=>parent is ambiguous, I'd recommend id=>comment_parent and id=>post_parent, or something. For now, I'd suggest we drop it entirely.

#8 @nacin
11 years ago

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

In 29045:

WP_Comment_Query: Add fields => 'ids' query var.

props mordauk.
fixes #28434.

#9 @nacin
11 years ago

Reworked the tests to ensure we actually had integers. (If get_comments() returned objects and so did our factory create() method, this would have silently failed. Since our factory methods use core APIs under the hood, you never know.) Also used assertCount.

#10 @mordauk
11 years ago

Thanks nacin!

#11 @SergeyBiryukov
11 years ago

The test fails for me:

1) Tests_Comment_Query::test_fields_ids_query
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 2
+    0 => 4
     1 => 3
-    2 => 4
+    2 => 2
 )

S:\home\wordpress\develop\tests\phpunit\tests\comment\query.php:199

#12 @SergeyBiryukov
11 years ago

In 29134:

Use assertEqualSets() instead of direct array comparison.

see #28434.

Note: See TracTickets for help on using tickets.