I have a post type 'location' that is a listing for each branch of a multi-branch company. I want to add a Left and Right arrow on each individual location post that will allow the users to cycle through the various locations. I'm trying to use the previous_post_link() and next_post_link() functions to achieve this, but when I use them, nothing is returned.

Here is my code for single-location.php:

<?php get_header(); ?>
    <div id="content">
        <div id="inner-content" class="wrap cf">
            <main id="main" class="m-all t-2of3 d-5of7 cf" role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Blog">
                <?php previous_post_link('%link', 'Previous post »'); ?> | <?php next_post_link('%link', 'Next post »'); ?>
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
                        <section class="entry-content cf" itemprop="articleBody">        
                            <h1><?php the_title(); ?></h1>
                           <?php the_content(); ?>            
                        </section> <?php // end article section ?>
                <?php endwhile; endif; ?>
<?php get_footer(); ?>

I've tried every variation on:

<?php previous_post_link('%link', 'Previous post »'); ?> | <?php next_post_link('%link', 'Next post »'); ?>

that I can find on this site, and many other places I've searched, and no matter which of the 30 location posts I view, all I see in that space is the vertical pipe separator (|). I've tried the code inside, and outside of the loop with the same results.

What am I missing?

  • 1
    bryantwebdesign.com/code/… – coopersita Oct 7 '15 at 20:29
  • Something is breaking your page, a filter, query_posts, bad custom query, it could be anything. Turn debug on, deactivate plugins, switch to a bundled theme etc. Update Wordpress – Pieter Goosen Oct 7 '15 at 20:31
  • I've already tried every version of the code on that page, prior to asking this question, and they all return nothing. – Joe Oct 7 '15 at 20:32
  • Have you actually tried what I suggested in order to debug this. The behavior you are seeing are not normal and is definitely caused by something outside of core, so it has to be something in you theme or in a plugin. You can try a million variations of the code and it will not work. You have to debug and establish where the issue is coming from. One other thing I forgot, flush your rewrite rules – Pieter Goosen Oct 8 '15 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.