• i have one CPT called ‘Socio’ with a taxonomy called ‘pagato’.
    i have 5 post of ‘Socio’ but only 3 have ‘pagato’ as taxonomy.
    when i view the single page i want navigation show next-link of the next post that has ‘pagato’ as taxonomy and NOT the link of the next post in general.
    how can navigate (show the link to the previous/next article) from single post to another only if is in the same taxonomy?
    i tried to use:

    <?php previous_post_link( ‘%link’, ‘%title’, true );
    next_post_link( ‘%link’, ‘%title’, true ); ?>

    with TRUE but it doesn’t works!!
    can anyone help me?
    thanks
    bye
    Maurizio

Viewing 5 replies - 1 through 5 (of 5 total)
  • Near as I can tell, you need to declare the taxonomy at the end for it to work, try:

    <?php previous_post_link( ‘%link’, ‘%title’, true, 'pagato' );
    next_post_link( ‘%link’, ‘%title’, true, 'pagato' ); ?>
    Thread Starter Maurizio Spicuglia

    (@nextart)

    it doesn’t show any link if set to TRUE!!
    this is my single page

    <div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    	        <?php twentythirteen_post_nav(); ?>
    				<?php get_template_part( 'content', 'single-socio' ); ?>
    					<?php comments_template(); ?>
    			<?php twentythirteen_post_nav(); ?>
    
    <?php
    previous_post_link( '%link', '%title', true, 'pagato' );
    next_post_link( '%link', '%title', true, 'pagato'); ?>
    <?php endwhile; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->

    That means that there aren’t any posts in your “pagato” taxonomy. Read the documentation here.

    Thread Starter Maurizio Spicuglia

    (@nextart)

    i’m sorry but i have two post in pagato taxonomy, the problem was just that.
    with this is show on single page the post’s taxonomy:

    $tipo_list = get_the_term_list( $post->ID, 'tipo', '<strong>tipologia:</strong> ', ', ', '' );
    
    echo &tipo_list;

    so it show on two of three post i have this:

    tipologia: pagato

    if i click on “pagato link” i obtain an archive page with two post. so i have post on taxomony pagato.

    Thread Starter Maurizio Spicuglia

    (@nextart)

    sorry…. i made a mistake.
    i have a taxonomy : tipo
    and a category : pagato

    so the previous and next link are right like this:

    <?php previous_post_link( '%link', '%title', $in_same_cat = true, $excluded_terms = '', $taxonomy = 'tipo' ); ?>
    <?php next_post_link( '%link', '%title', $in_same_cat = true, $excluded_terms = '', $taxonomy = 'tipo' ); ?>

    my error.

    i’m newbie on CPT.
    by
    Maurizio

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to show next post link of CPT only if is in same taxonomy’ is closed to new replies.