3

I have a custom post type called "exhibitions" that uses the native "category" taxonomy. I have three categories: Current, Past, and Featured. Posts get marked either Current or Past and some are also marked as Featured.

I want my next/prev links on single pages to exclude the 'featured' category (tag_ID=21) so that my current and past posts don't cross over when users are using post navigation, but I can't seem to get this to happen. I have tried:

get_next_post(true,'21'), get_next_post(false,'21') and pretty much every other permutation of arguments, but my Past/Featured posts continue to show up adjacent to my Current/Featured posts in the post navigation.

1

Did you try with: get_adjacent_post ?

get_adjacent_post(false, 'YourID', false);

wp topic: get_adjacent_posts-exclude-category-syntax

  • 1
    Please add more detail to this answer. An answer here should stand alone and not be dependent upon a third party link. – s_ha_dum Apr 29 '14 at 14:53
1

The 2nd parameter enables you to exclude category I.D's

 $excluded_categories
(string) (optional) Excluded categories IDs.

    Default: '' 

 <?php get_next_post( $in_same_cat, $excluded_categories ) ?> 

Source https://codex.wordpress.org/Function_Reference/get_next_post

Same with get_adjacent_post()

 <?php get_adjacent_post( $in_same_cat, $excluded_categories, $previous ) ?> 
1

In Word.ress 3.9 (and still in 3.9.1) there's a bug concerning the excluded terms in get_adjacent_post(). There's a plugin to fix that bug.

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.