I can't for the life of me get this to work - this is the code in my single-osu_work.php file which is used for this post type, but I can't get the next and previous post links to appear - can you see a problem? I've tried putting the pagination links within the loop but still nothing.



if (have_posts()) : while (have_posts()) : the_post(); ?>
    <article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
        <h1 id="mainheading"><?php the_title(); ?></h1>
        <?php the_content(); ?>
        <footer class="postmetadata">Date: <?php the_date('Y'); ?></footer>
    <?php endwhile;
else : ?>
    <article id="nada">
        <h2 id="mainheading">Nothing found</h2>
        <p>Apologies, but you've come across a page that can't be found.</p>
        <p>Please use the search function or continue browsing.</p>
        <?php echo get_search_form(); ?>
<?php endif; ?>

    <div class="next-posts"><?php next_post_link('%link', 'Newer entry &gt;', true) ?></div>
    <div class="prev-posts"><?php previous_post_link('%link', '&lt; Older entry', true) ?></div>
    <div class="clear">&nbsp;</div>
  • 1
    They should be inside the loop - you might want to update your code.
    – vancoder
    Aug 16, 2013 at 16:40
  • Unfortunately, I already tried that and it doesn't work, the navigation links don't appear, only the div markup around them...
    – Osu
    Aug 18, 2013 at 9:29
  • Update: I can get this to work if I move it into the loop but only use next_post_link() not next_post_link('%link', 'Newer entry &gt;', true) - any idea why that might be? Is it because it's a custom post type and you can't rename post pagination links? I'd like to rename the link if at all possible. Thanks
    – Osu
    Aug 18, 2013 at 9:33
  • Just remove the "true" part. That worked for me.
    – Pete
    Jan 1, 2017 at 4:23

3 Answers 3


Ok, I found the solution in terms of getting the links to appear, however, I needed to remove the 'true' argument for only moving between posts in the same category/taxonomy.

Is that right that you can't restrict the posts linked to so that they're only the ones within the same taxonomy? Here's the correct code and as vancoder says, it needs to appear within the loop (I placed this just before endwhile;):

<div class="next-posts"><?php next_post_link('%link', 'Newer entry &gt;') ?></div>
<div class="prev-posts"><?php previous_post_link('%link', '&lt; Older entry') ?></div>

As this is a custom post type with a custom taxonomy, I assume the pagination is breaking because Wordpress is looking for a 'category' as if these were normal posts? Is there any way to make this work so that only Work posts within my custom taxonomy are returned?

  • Yes, the functions only work with the 'category' taxonomy. I'm not aware of a method of over-riding this.
    – vancoder
    Aug 19, 2013 at 6:22

As of WordPress 3.8 you can specify a taxonomy as the fifth parameter. In your case it would be something like:

<?php previous_post_link( '%link', __( 'Older Entry &gt;', 'sometextdomain' ), true, '', 'somecustomtaxonomy' ); ?>
<?php next_post_link( '%link', __( 'Newer Entry &gt;', 'sometextdomain' ), true, '', 'somecustomtaxonomy' ); ?>

Check the Codex for more info http://codex.wordpress.org/Function_Reference/previous_post_link


Make sure if you have made a custom wp_query call before the next_post_link() / previous_post_link() calling and has not reset the query to the default.

In that case please use wp_reset_query after the use of custom wp_query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.