• When we click each post on Category page and click Previous/Next on Single post page. I would like a Previous/Next post same category. So I try to custom ‘single.php’

    <?php $prev_post = get_previous_post( true );
    if (!empty( $prev_post )): ?>
    <?php $next_post = get_next_post( true );
    if (!empty( $next_post )): ?>

    but it doesn’t work. And I try to look back get_previous_post() in \wp-includes\link-template.php and custom a code on below

    function get_previous_post( $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' ) {
    	return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy );
    }
    function get_next_post( $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' ) {
    	return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy );
    }

    it still doesn’t work also. Could someone suggest me how to make Previous/Next in same category?

    Thank you

  • The topic ‘Previous/Next in same category’ is closed to new replies.