WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>
share|improve this question
They should be inside the loop - you might want to update your code. – vancoder Aug 16 '13 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 '13 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 '13 at 9:33
up vote 3 down vote accepted

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?

share|improve this answer
Yes, the functions only work with the 'category' taxonomy. I'm not aware of a method of over-riding this. – vancoder Aug 19 '13 at 6:22
Ok, thanks for your help Vancoder – Osu Aug 19 '13 at 7:05

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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