custom post types - get_the_post_navigation not working

admin2025-01-08  5

I am using a custom post type with 9 posts. Whichever post I click on the_post_navigation shows the same post. When I go to that post it shows the only other post in its taxonomy. From then on I can only navigate between the two posts in this taxonomy. I'm using the code below:

$args = array(
    'prev_text' => '<span class="meta-nav">&lt;</span> Previous: %title',
    'next_text' => 'Next: %title <span class="meta-nav">&gt;</span>',
);
echo get_the_post_navigation( $args );

I am using a custom post type with 9 posts. Whichever post I click on the_post_navigation shows the same post. When I go to that post it shows the only other post in its taxonomy. From then on I can only navigate between the two posts in this taxonomy. I'm using the code below:

$args = array(
    'prev_text' => '<span class="meta-nav">&lt;</span> Previous: %title',
    'next_text' => 'Next: %title <span class="meta-nav">&gt;</span>',
);
echo get_the_post_navigation( $args );
Share Improve this question asked Sep 17, 2022 at 15:23 BadgerBadger 1931 gold badge3 silver badges10 bronze badges 2
  • That's odd — the code works fine for me! You could check to see if there are any filters being applied that might cause a conflict. A fast way to test if there's anything funny going on would be to change the theme and use the Health Check and Troubleshooting plugin to disable plugins temporarily. – Nabha Cosley Commented Sep 18, 2022 at 4:59
  • Having looked at the query using the query monitor plugin, it seems as if the query looks for posts that are older or newer than the current post. All the posts were created on the same day except one. if SQL ignores the time and only goes on the date, it would explain it. – Badger Commented Sep 19, 2022 at 10:32
Add a comment  | 

1 Answer 1

Reset to default 0

What is the context? How did you create your nine custom posts?

A possible cause is importation from e.g. a spreadsheet (CSV); I have a situation where newly-made custom posts get correct links, but all imported posts have wrong links:

  • All except two posts, namely post-ID "1941" and "1987", link for "previous" to "1941" and for "next" to "1987".
  • Post "1941" doesn't have a "previous", and "next" is post "1943"
  • Post "1987" doesn't have a "next", and "previous" is "1942"

"1987" is the first not-imported-from-spreadsheet post; and "1941" is by no means the oldest imported (that's "1902"; all imported are numbered consecutively 1902, 1903, ... , 1977).

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266531a1128.html

最新回复(0)