Opened 8 years ago
Closed 3 years ago
#36907 closed enhancement (fixed)
Improved sticky post query
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Query | Keywords: | |
Focuses: | performance | Cc: |
Description
Currently with the WP_Query class calls a get_posts to get a array of posts to include on the home / blog page. However this get_posts will not obey parameters passed to the main WP_Query class.
Attachments (4)
Change History (24)
#3
@
3 years ago
36907.patch looks good to me.
Not to self so I don't look it up again, get_posts()
has no_found_rows
set already so it's not needed here.
This ticket was mentioned in PR #2445 on WordPress/wordpress-develop by spacedmonkey.
3 years ago
#4
- Keywords has-unit-tests added; needs-unit-tests removed
Trac ticket: https://core.trac.wordpress.org/ticket/36907
spacedmonkey commented on PR #2445:
3 years ago
#7
Merged.
#8
@
3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
It's not quite clear why [52982] removed the 'nopaging' => true
argument from the get_posts()
call in question, as neither the ticket nor the commit message mention the removal.
With that change, only 5 sticky posts are displayed now. This is a backward compatibility break, see #55444.
36907.diff restores 'nopaging' => true
and reorder the parameters for consistency with similar calls elsewhere.
#12
@
3 years ago
Good catch @SergeyBiryukov . No paging / posts per page was removed at the last minute. It should not have been. I have created a follow on PR at #2454. Can you take a look?
This ticket was mentioned in PR #2454 on WordPress/wordpress-develop by spacedmonkey.
3 years ago
#13
Trac ticket: https://core.trac.wordpress.org/ticket/36907
This ticket was mentioned in PR #2454 on WordPress/wordpress-develop by spacedmonkey.
3 years ago
#14
Trac ticket: https://core.trac.wordpress.org/ticket/36907
peterwilsoncc commented on PR #2454:
3 years ago
#15
LGTM.
Are you able to put the following test in to Tests_Query_Stickies
be sure it's not broken next time?
{{{php
/
- Ensure all sticky posts are included, no matter how many. *
- @ticket 36907 */
public function test_query_should_return_all_stickies() {
$old_option = get_option( 'sticky_posts' );
foreach ( self::$posts as $post_id ) {
stick_post( $post_id );
}
$q = new WP_Query( array( 'post_type' => 'post' ) );
22 sticky posts, 1 hello world.
$this->assertCount( 23, $q->posts );
update_option( 'sticky_posts', $old_option );
}
}}}
I am not sure if the options table is included in the test suite's DB transaction. If it is then the last line can be dropped as the table should bre reset as part of tear down.
#16
@
3 years ago
- Keywords commit removed
Removing commit keyword while the follow up commit is finalised.
spacedmonkey commented on PR #2454:
3 years ago
#17
@peterwilsoncc Added a unit test.
Added patch