0

All I want to do is link to the next post in the same category, and for the life of me I can't see what's wrong with my code. Does in_same_term work for everyone else?

  <?php $prev_post = get_adjacent_post( true, '18 and 20 and 10 and 21 and 19 and 22 and 17', true, 'portcats' );  ?>
   <?php if ( !empty( $prev_post ) ): ?>
     <?php // get the id of the category you just came from
              $term_id = $_REQUEST['cat']; ?>
      <a href="<?php echo $baseurl . '/portfolio/' . $prev_post->post_name; ?>/?cat=<?php echo         $term_id; ?>"><span class="plain-text">Previous</span> PROJECT</a>
   <?php endif; ?>
  • This may or may not be the problem but the second argument should be "Array or comma-separated list of excluded term IDs". What you have is neither. – s_ha_dum Nov 3 '14 at 22:35
  • @s_ha_dum, actually, if you look at the link-template, the delimiter is "and". I've also tried to go with '' (default), with no luck as well. – acrane Nov 3 '14 at 23:01
  • There is backwards compatibilty code that allows the "and". That usage is deprecated. You should not be using it. – s_ha_dum Nov 3 '14 at 23:16
1

The arguments for get_adjacent_post is not formatted correctly. $excluded_terms needs to be either a string or an array. Also be careful with the category. If 'portcats' is a category name and not a taxonomy, that won't work. This is looking for posts that are in the same 'portcats' taxomony with certain terms in 'portcats' excluded. The same category is provided by the first(if in multiple) category the current post is in.

$excluded_terms (array or string) (optional) Array or comma-separated list of excluded term IDs.

<?php $prev_post = get_adjacent_post( true, '18,20,10,21,19,22,17', true, 'portcats' );  ?>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.