Great work on this plugin! I encountered an issue which I have resolved but I thought I should let you know about it. I performed an import to populate my database, therefore many post_dates are the same. When I clicked on “Update and Next” the plugin was skipping several posts.
Here’s the problem:
Your function get_adjacent_post() checks for the adjacent post based on post_date with the “>” and “<” operators. This skips the adjacent post if they have the same post date, which they did in my case.
Here’s how I solved it:
First I changed the operators to “>=” and “<=”. Then I added an additional WHERE clause to disregard the current post because “>=” and “<=” will always return the current post. This fix was applied on lines 92-95 of class-lb-save-and-then-utils.php.
$op = $dir == 'next' ? '>=' : '<='; $op2 = $dir == 'next' ? '>' : '<'; $order = $dir == 'next' ? 'ASC' : 'DESC'; $exclude_states = get_post_stati( array( 'show_in_admin_all_list' => false ) ); $additionnal_where = 'AND p.ID '.$op2.' \''.$post->ID.'\'';
Finally, I added p.ID to the orderby clause on line 110 to ensure that WordPress grabs the next ID if the post_dates are equal.
ORDER BY p.post_date, p.ID $order LIMIT 1
There’s probably a better way to achieve this but since I am not familiar with your plugin I figured I should let you know about my experience so you can consider including a solution in a future update. Also, I understand that my situation might be too localized to warrant a bug fix. Thanks again for the super work on this plugin! It is extremely useful!
- The topic ‘Next post skipped when post date are equal – PATCHED’ is closed to new replies.