[wp-trac] [WordPress Trac] #28399: Allow WP_Query to query by comment_count column of CPT/posts table
WordPress Trac
noreply at wordpress.org
Mon Oct 13 20:21:49 UTC 2014
#28399: Allow WP_Query to query by comment_count column of CPT/posts table
---------------------------+-----------------------------
Reporter: ramon fincken | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Query | Version: 4.0
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
---------------------------+-----------------------------
Changes (by boonebgorges):
* keywords: has-patch needs-testing => needs-patch
* milestone: Awaiting Review => Future Release
Comment:
I this this is a pretty good idea. A couple of comments (no pun intended):
* Let's not add two new params ('comment' and 'comment_count'). This seems
unnecessary and confusing to me. I suggest having one: 'comment_count'.
You can pass an array of 'count' and 'compare', or you can pass it a
number, which gets parsed into `array( 'count' => $number, 'compare' =>
'=' )`.
* The unit tests look really comprehensive - thanks so much for that.
Let's move them to `tests/phpunit/tests/query/commentCount.php`, since
this is a new feature for WP_Query.
* In the unit tests: no need to do `http_build_query()` - just pass an
array. No need to set dummy 'post_content' or 'post_type' on the factory
posts - just use the defaults (`$p1 = $this->factory->post->create()`,
with no arguments). Testing `found_posts` is not precise enough - please
get the found post IDs and use `assertEqualSets` to compare with
`$this->q->posts`. I recommend using the following arguments for
`WP_Query`, to minimize overhead:
{{{
$this->q->query( array(
'fields' => 'ids',
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'comment_count' => array(
'count' => 5,
'compare' => '>',
),
) );
$expected = array( $p1, $p2 );
$this->assertEqualSets( $expected, $this->q->posts );
}}}
The functionality itself looks pretty nice, so with some of these changes
I think we can put this in. Thanks for the contribution!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28399#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list