0

I have a category called "Featured Photo" that is category ID 2. I want to create next-post and previous-post links that contain links only for the next and previous posts in category ID 2. However, many "Featured Photo" posts also belong to more than one category, and I have so far been unable to find a solution that limits the "Next" and "Previous" links to category 2. If I do not exclude any categories in the previous_post_link() and next_post_link() calls, those links are populated with the URL to the previous/next post in one of the other multiple categories assigned to the "Featured Photo" posts. Thus, I created a variable containing an array of all of the other category IDs and added it to the exclude portion of the previous_post_link() and next_post_link() calls, but that is just resulting in the links not showing up at all. (I've searched extensively for a solution, and haven't found anything that works.)

function featured_photo() {
        global $post;
        if (is_single() && in_category(2)) {
        $category = array(1,3,4,5,6,7,8,9,67,68,69,74,76,78,82);
        $pod = get_post_meta($post->ID, 'pod', true);
        echo '<div id="pod">';
        echo the_title( '<h1 class="entry-title">', '</h1>' );
        echo $pod;
        previous_post_link( '%link', 'Previous photo', true, $category );
        next_post_link( '%link', 'Next photo', true, $category );
        echo '</div>';
        }
}
add_action( 'genesis_before_content','featured_photo');
1
  • Still stumped here. Is there some way to call a previous_post_link and next_post_link from category 2 specifically as opposed to trying to exclude categories...?
    – jonzal
    Jun 19 at 21:12
0

did you search around the functions get_adjacent_post() ?

A long time ago, I made a Woocommerce plugin (an old outdated Woocommerce product navigation on the repo) that use it in the same case and it used to work.

The class I created, use a fallback function to get all ids to exclude.

Hope it helps ;)

1
  • Unfortunately, this didn't help. Thanks for the suggestion, though.
    – jonzal
    Jun 19 at 21:11

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.