2.x Improve Timber::get_post_by()#2195
Merged
jarednova merged 6 commits into2.x-get-post-byfrom Feb 28, 2020
Merged
Conversation
When we check for the date, the ID of the post we expect to be returned needs be higher than the ones that should be ignored in order for the test to run correctly
This makes it possible to order by anything we want
Codecov Report
@@ Coverage Diff @@
## 2.x-get-post-by #2195 +/- ##
=====================================================
+ Coverage 94.83% 96.07% +1.23%
- Complexity 1536 1537 +1
=====================================================
Files 50 50
Lines 3912 3921 +9
=====================================================
+ Hits 3710 3767 +57
+ Misses 202 154 -48
Continue to review full report at Codecov.
|
Member
|
Looks good! You sure caught my play-by-play as I was trying to get this to a good place last week. Seems like a crazy little bit of WordPress weirdness left in by the WordPress gods that d6f95d3 solves. I totally agree with the last option (I was already feeling a bit unsure about "assuming" that a user would want the oldest) — so this makes it a pure default/option. I'm pulling down now to add that last piece ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: #2169
This pull request adds on top of #2169. But because I had to change more than I thought, this comes in a separate pull request so we can discuss it first.
In 302e08b, you changed the order the posts were created. This go me thinking. If we want to check for the oldest post and make sure we ignore the post ID, which is an indicator of the order the posts were created in, then the post expect to be returned shouldn’t be the first to be created.
In 58d24dd, you changed the parameter in the test to
any, which is not the same as an array of post types. Because of this, a different function to search for posts was used, making the tests pass. I think we should check for both.I figured out that
post_exists()andget_page_by_title()won’t work if we go for the oldest post and don’t want to sort by ID. That’s why I replacedpost_exists()andget_page_by_title()with our own query in d6f95d3. I usually try to avoid creating direct queries, but I think there’s no easier way to search for a post title.But by doing that, we open a new possibility to make the function more useful. We could add order arguments:
This way, developers could decide on their own to change the logic a post is selected when there are multiple posts available.