Cant get paginations on single.php to work with my custom post types

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. ?>

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

</div><!--endwrap-->

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?

Solutions Collecting From Web of "Cant get paginations on single.php to work with my custom post types"

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

EDIT 1

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' );

EDIT 2

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.

Example:

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

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 ) {
        return;
    }

    ?>
    <nav class="navigation post-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
        <div class="nav-links">
            <?php
            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' ) );
            endif;
            ?>
        </div><!-- .nav-links -->
    </nav><!-- .navigation -->
    <?php
}
endif;

And then add the tag before the endwhile

      // Previous/next post navigation.
    twentyfourteen_post_nav();
                    }
    endwhile; ?>