Set ignore_sticky_posts=true as default wp_query argument#1813
Set ignore_sticky_posts=true as default wp_query argument#1813jarednova merged 12 commits intotimber:masterfrom
Conversation
…fetching too many posts when using stickies
Codecov Report
@@ Coverage Diff @@
## master #1813 +/- ##
============================================
+ Coverage 95.04% 95.05% +0.01%
- Complexity 1556 1563 +7
============================================
Files 48 48
Lines 3672 3682 +10
============================================
+ Hits 3490 3500 +10
Misses 182 182
Continue to review full report at Codecov.
|
|
@bartvanraaij thanks for this PR. I think this reveals one of the differences between WP's It appears that WP's I (think) merging this would fix the Can you take a look to see if there's a way (perhaps using a |
|
Thanks for the feedback. I will take a look at that. |
|
@jarednova @bartvanraaij If we want to make them working the same shouldn't we also add:
|
|
@palmiak agreed, while we're here we may as well get the other parts of |
… get_posts() call
jarednova
left a comment
There was a problem hiding this comment.
I did a fair amount of reorganization but @bartvanraaij's basic formation is the right one. By pulling this into PostGetter and tying it directly to the get_posts method, we've got a pretty simple framework to address #1812 and add any other get_posts vs. WP_Query quirks are out there
|
@palmiak I made some adjustments based on @bartvanraaij's code. I think this is in a good place, but I'd love your eyes in a review so we can make sure — thanks! |
|
It looks good @jarednova . I just saw one thing in 2.0 branch related with this, but I'll open an issue for this. |
|
@palmiak yeah, good call on how/if this comes into 2.0 — let's discuss it there |
|
Thank you @jarednova . This totally slipped my attention. |
|
all good @bartvanraaij ! Thanks again for your contribution. I'll release later this week to Composer and WP.org! |
| } | ||
| if ( isset($query->query) && !isset($query->query['supress_filters']) ) { | ||
| $query->set('supress_filters', true); | ||
| } |
There was a problem hiding this comment.
It should be suppress_filters instead of supress_filters!!! 🚨
ref #1813 -- suppress spelling fixed
... to prevent fetching too many posts when using stickies.
This fixes #1812 and makes sure that
Timber::get_posts()produces the same output as WPget_posts()when using sticky posts.Ticket: #1812
Issue
See my bug report: when using sticky posts; the incorrect amount of posts in returned.
Solution
I've added a method
set_query_defaultstoQueryIteratorwhich is hooked atpre_get_posts. The method setsignore_sticky_poststotrueif not set otherwise.This is the same behaviour as WP
get_posts, seewp-includes/post.php:1759.Impact
Other than fixing this bug, no impact, presumably.
Testing
I've added
testGettingPostsWithStickiesReturnsCorrectAmountOfPostsintest-timber-post-getter.phpIf you comment out the new
add_action set_query_defaultsatQueryIterator.php:26the test will fail. With my fix, it will pass.