I'm using custom post types and custom fields plugins for my custom post types.

I have all other paginations working smoothly on my website except for my single.php. I have a custom post type of "Products" with dozens of products assigned to a custom taxonomy of "Types" and so far I've gotten all of the pagination on my other pages to work with custom queries.

However, in single.php, I dont need to use custom queries so I'm not sure if Im going about this the right way.

Here is my very simple code:

<div class="wrap">
<?php while ( have_posts() ) : the_post(); ?>

//my custom post type content
<?php the_field('image'); ?>
<?php the_content(); ?>

        <?php endwhile; // end of the loop. ?>

<?php previous_post_link('&laquo; Prev') ?>
<?php next_post_link('Next &raquo;') ?>


When I add the next and previous post links, I can see the Next and Prev link and the bottom of my page, but it is NOT a link to the next or prev page. Its just plain ol static text that does nothing.

Im not using custom queries on this one because like I said you dont have to for single.php to display your custom post type content.

Any suggestions?

  • Have you added the 'paged' and 'posts_per_page' parameters in the WP_Query()? Could you add that code too in your question.
    – Domain
    Nov 10, 2014 at 11:17
  • 1
    im not using a custom query tho, just a regular loop. single.php doesn't need a custom query to display custom post types Nov 10, 2014 at 11:18

2 Answers 2


You will need to add %link to the first parameter ($format) of next_post_link and previous_post_link

This will generate the html links to the respective posts


Just on your statement about custom queries, did you had a look at how pre_get_posts can be used to alter the main query as needed. It is never a good idea replacing the main query with a custom query.

Here is an example on adding your custom post type to your homepage

function include_post_type( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', array('post', 'my_post_type') );
add_action( 'pre_get_posts', 'include_post_type' );


Just on your comment. The posts are displayed according to post date, either ASC or DESC depending on your blog settings.

You can set both links to only page to the next/previous post within the same term. Have a look at the third parameter ($in_same_term) and fifth parameter ($taxonomy)

By default $in_same_term is set to false and $taxonomy is set to category. You can set this accordingly.


next_post_link( '%link', 'Next post in types', TRUE, ' ', 'types' ); 

This will page to the next post within the same term that this particular post belongs to within the types taxonomy

  • Check my update. On your code above, if it works as expected, I would not mess with it right now. Check this post I've a while ago. You can play around with the code. Nov 10, 2014 at 12:10
  • Hey thanks for all the help Pieter really appreciate it, im going to bed but i'll talk to you through chat later on and show you my taxonomy.php code for my products if you'd like. Nov 10, 2014 at 13:26
  • Let us continue this discussion in chat. Nov 10, 2014 at 13:43

You could also create a template tag like what the Twenty Fourteen default theme includes rather than hard code it into the single file.

if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :

function twentyfourteen_post_nav() {
    // Don't print empty markup if there's nowhere to navigate.
    $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    $next     = get_adjacent_post( false, '', false );

    if ( ! $next && ! $previous ) {

    <nav class="navigation post-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
        <div class="nav-links">
            if ( is_attachment() ) :
                previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
            else :
                previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
                next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
        </div><!-- .nav-links -->
    </nav><!-- .navigation -->

And then add the tag before the endwhile

      // Previous/next post navigation.
    endwhile; ?>

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.