Trying to get_adjacent_post - in same category not working

this is my first time here. I need my previous and next posts to show only posts on the same category. But I don't know how to do it.

This is the code in my template (called Valenti) it is in a file called core.php

/*********************
 CLEAN NEXT/PREVIOUS LINKS
*********************/

if ( ! function_exists( 'cb_previous_next_links' ) ) {
    function cb_previous_next_links() {

          $cb_previous = get_adjacent_post( false, '', true );
          $cb_next = get_adjacent_post( false, '', false );
          if ( ( $cb_next != NULL ) || ( $cb_previous != NULL ) ) {

              $cb_empty = 'div class=cb-empty' . __(x, cubell).'/div';

              echo'div id=cb-previous-next-links class=cb-post-footer-block clearfix';

              if ( $cb_previous != NULL ) {

                         echo 'div id=cb-previous-linka href=' . get_permalink($cb_previous) . 'i class=fa fa-long-arrow-left/i/a';
                         previous_post_link('%link');
                         echo '/div';

              } else {
                  echo $cb_empty;
              }
               if ( $cb_next != NULL ) {
                         echo 'div id=cb-next-linka href=' . get_permalink($cb_next) . 'i class=fa fa-long-arrow-right/i/a';
                         next_post_link('%link');
                         echo '/div';

              } else {
                  echo $cb_empty;
              }

              echo '/div';
           }
    }
}

I have been trying many things, but none is working, it is not showing posts on the same category.

tryied doing this, but it is not working and don't know why

 $cb_previous = get_adjacent_post( true, '', true, 'category' );
  $cb_next = get_adjacent_post( true, '', false, 'category' );

what can I do? Not a coder, so I need you to explain in details or with examples if I have to add a snippet in functions or to modify the code above. Thanks in advance!

Topic next-post-link Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.