Opened 7 years ago
Last modified 3 years ago
#42936 assigned defect (bug)
get_adjacent_post won't find any posts that are published in the same minute
Reported by: | sheepysheep60 | Owned by: | johnbillion |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.9.1 |
Component: | Posts, Post Types | Keywords: | good-first-bug has-patch close |
Focuses: | Cc: |
Description
get_adjacent_post
won't find any posts that are posted in the same minute, even if they are technically posted before or after the other post.
This sounds silly but if you use a clone function to create multiple posts for a website, then you you can't navigate them using links created with get_previous_post
or get_next_post
.
Change History (21)
This ticket was mentioned in Slack in #core by noisysocks. View the logs.
4 years ago
#2
@
4 years ago
- Component changed from General to Posts, Post Types
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 5.6
#3
@
4 years ago
@talldanwp I don't think this can solve this issue, I applied this approach and another approach and I think this won't completely solve this issue, plz check the following video recorded: https://www.youtube.com/watch?v=ASMoo0RmXkM
#4
follow-up:
↓ 5
@
4 years ago
I haven't had the chance to test this but I think it could be solved by one of two approaches:
- change the clause to
WHERE p.post_date >= $current_post_date AND p.ID != $current_post_id ORDER BY p.post_date, p.ID
- use the
WHERE
clause @talldanwp suggests above and use PHP to remove the current post ID
For previous posts, the clause would need to be reversed.
#5
in reply to:
↑ 4
@
4 years ago
Replying to peterwilsoncc:
- change the clause to
WHERE p.post_date >= $current_post_date AND p.ID != $current_post_id ORDER BY p.post_date, p.ID
- use the
WHERE
clause @talldanwp suggests above and use PHP to remove the current post ID
I tried both solutions on this video https://www.youtube.com/watch?v=ASMoo0RmXkM and I think this generates another issue.
This ticket was mentioned in Slack in #core by sergey. View the logs.
4 years ago
This ticket was mentioned in PR #617 on WordPress/wordpress-develop by dpanta94.
4 years ago
#7
- Keywords has-patch added; needs-patch removed
The date operator changed to include equals.
A post id operator was added.
In the where clause, we ensure that the post id is not equal to the active's one.
We order by post id.
Trac ticket: https://core.trac.wordpress.org/ticket/42936
#8
@
4 years ago
Hello there! I applied a possible fix. Please take a look on my pull request here https://github.com/WordPress/wordpress-develop/pull/617
Thanks!
This ticket was mentioned in PR #619 on WordPress/wordpress-develop by dpanta94.
4 years ago
#9
After further testing, I found out that my previous patch for this issue would work only if we could assume that smaller post ID equals older post date, which we should not.
In this patch, we use a dynamic LIMIT Clause. The limit is being determined by the number of posts with the same post_date.
We use wpdb::get_results instead of wpdb::get_var.
We determine the next or previous post ID based on the position of the active's post ID in the array of the results.
Trac ticket: https://core.trac.wordpress.org/ticket/42936
This ticket was mentioned in PR #622 on WordPress/wordpress-develop by dpanta94.
4 years ago
#10
This PR is an updated version of https://github.com/WordPress/wordpress-develop/pull/619 which mainly focuses on the case where $excluded_terms is not empty.
When the active post's term(s) is included in the $excluded_terms, the active post id is not included in the $results of $wpdb->get_results(). In that case, we should return the first post ID inside the $results array if it exists.
Trac ticket: https://core.trac.wordpress.org/ticket/42936
#11
@
4 years ago
There is no way to get rows in the same order in which they are stored in a database for sorting purposes.
The solution can be is to get all ID's with the same post_date and if they're more than one, for the previous post take the previous in this result if it exists, and if not - get the post with a date less than the current date, and exactly the same process for next post. An alternative solution could be to check the post_date before save / update and make it unique by adding some amount of milliseconds.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#14
@
4 years ago
Patch added in https://core.trac.wordpress.org/ticket/47642#comment:20
This ticket was mentioned in Slack in #core by lukecarbis. View the logs.
4 years ago
#16
@
4 years ago
- Keywords close added; early removed
As suggested, further testing and work can be done in https://core.trac.wordpress.org/ticket/47642
This ticket was mentioned in Slack in #core by sergey. View the logs.
4 years ago
#18
@
4 years ago
- Milestone changed from 5.7 to 5.8
- Owner set to johnbillion
- Status changed from new to assigned
This is been worked on with #47642 which has been moved the 5.8 milestone. I'll move this to match and assign to @johnbillion in line with the other ticket.
Thanks for reporting @sheepysheep60. We discussed this during a triage session in slack (https://wordpress.slack.com/archives/C02RQBWTW/p1601963248296700) and agreed this looks like a bug, it was mentioned in the triage that the cause seems to be: