0

I have post type testimonials.

I am listing that testimonials by specific taxonomy with read more link.

When user click on read more link which is get_permalink( $post ), and redirect to specific page then i want to show previous and next post link with same taxonomy of current post?

If you require any more info then let me know.

I have added true as third element for it, but don't worked

previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'twentytwelve' ) . '</span> %title' ,true );
Yatin Mistry
  • 1,246
  • 2
  • 13
  • 35
  • What code have you written so far? – i alarmed alien Oct 08 '14 at 10:56
  • I don't have found anything for it so come here.Function get_permalink( $post ); will generate post link. – Yatin Mistry Oct 08 '14 at 12:33
  • possible duplicate of [show post from the same category when you click previous/next button wordpress](http://stackoverflow.com/questions/19505829/show-post-from-the-same-category-when-you-click-previous-next-button-wordpress) – i alarmed alien Oct 08 '14 at 12:42
  • @ialarmedalien i have checked i need form same taxonomy. i am new to wordpress. – Yatin Mistry Oct 08 '14 at 12:46
  • Your post just talks about categories--please edit your question (not just the title) so it is clear exactly what you are trying to do. Thanks! – i alarmed alien Oct 08 '14 at 12:49
  • @ialarmedalien thanks for the update. I have used the pluging for it. strong testimonials https://wordpress.org/plugins/strong-testimonials/ where they have used word category so it creates confusion. – Yatin Mistry Oct 08 '14 at 12:52

2 Answers2

2

Refer this Link

I found solution as below

Go your single.php file

// Only for Testimonial

if(get_post_type( $post )=="wpm-testimonial")
{

    $terms = array_shift(get_the_terms($post->ID, 'wpm-testimonial-category'));


    // get_posts in same custom taxonomy
    $postlist_args = array(
        'posts_per_page'  => -1,
        'orderby'         => 'ID title',
        'order'           => 'ASC',
        'post_type'       => 'wpm-testimonial',
        $terms->taxonomy  => $terms->slug
    );

    $postlist = get_posts( $postlist_args );

    // get ids of posts retrieved from get_posts
    $ids = array();
    foreach ($postlist as $thepost) {
        $ids[] = $thepost->ID;
    }

    // get and echo previous and next post in the same taxonomy
    $thisindex  = array_search($post->ID, $ids);
    $previd     = $ids[$thisindex-1];
    $nextid     = $ids[$thisindex+1];

    ?>
    <nav class="nav-single">
    <?php

        if ( !empty($nextid) ) {

            echo '<span class="nav-previous"><a rel="next" href="' . get_permalink($nextid). '">Previous</a></span>';

        }

        if ( !empty($previd) ) {

    echo '<span class="nav-next"><a rel="prev" href="' . get_permalink($previd). '">Next</a></span>';

        }

    ?>
    </nav><!-- .nav-single -->

    <?php
}else{

    // Your Default Previous/Next Links in single.php file
}
?>
Yatin Mistry
  • 1,246
  • 2
  • 13
  • 35
1

EDIT: OP changed his question - so my solution is no longer correct.

I think you can find your solution in the Wordpress Codex - http://codex.wordpress.org/Template_Tags/next_post_link

Previous post within same category (Link as text)

 <?php previous_post_link('%link', 'Previous in category', TRUE); ?> 

Next post within same category (Link as text)

<?php next_post_link( '%link', 'Next post in category', TRUE ); ?>
retober
  • 366
  • 3
  • 17