Closed MichelleBlanchette closed 1 year ago
So this is actually a ridiculous situation... Unfortunately, the post navigation links use get_adjacent_post()
which uses a raw SQL query with $wpdb->get_var()
rather than an actual WP_Query
object. Also, there's no hook to filter the entire query or result. You can only filter each part of the query like JOIN, WHERE, and SORT: https://developer.wordpress.org/reference/functions/get_adjacent_post/
This is not worth the effort. I've been reviewing WordPress source code to figure out the best way to handle this.
Ultimately, I think you'd just filter the resulting "adjacent post links" but it'd require repeating the templating code that WordPress core does which is a maintenance hassle.
add_filter( 'next_post_link', __NAMESPACE__ . '\adjacent_post_link', 10, 5 );
add_filter( 'previous_post_link', __NAMESPACE__ . '\adjacent_post_link', 10, 5 );
function adjacent_post_link( $output, $format, $link, $post, $adjacent ) {
// error_log( print_r( func_get_args(), true ) );
return $output;
}
I'd rather the links be wrong than deal with this mess for hours.
It's not obvious to me how the posts navigation is determined, so some investigation is needed. Just a guess that it has something to do with
menu order
perhaps..? However, I know that it doesn't match the display ordering on the archive page which is sorted by the ACF date field.Be sure to update the blog post, too, with this gotcha once you figure it out: https://purpleturtlecreative.com/blog/2022/03/how-to-sort-wordpress-posts-by-acf-date-field-values/