WordPress.org

Ready to get started?Download WordPress

Forums

next_post_link/previous_post_link exclude category (11 posts)

  1. sdjentertainment
    Member
    Posted 1 year ago #

    Hey Hey,

    I've been doing some research and haven't come across a solid answer as of yet, so I though I would reach out for a hand.

    In the single.php file I have been using the next_post_link/previous_post_link as per the codex supplied by WP (https://codex.wordpress.org/Function_Reference/next_post_link).

    The second I change around the code from
    <?php next_post_link('%link', 'Next post in category', TRUE, '13'); ?>
    to
    <?php next_post_link('%link', 'Next post in category', FALSE, '58'); ?>
    things stop working.

    Any idea's

    Cheers,
    Simon

  2. Kegan Quimby
    Member
    Posted 1 year ago #

    FALSE is the default, so just leave it out

    <?php next_post_link('%link', 'Next post in category', '', '58'); ?>

  3. sdjentertainment
    Member
    Posted 1 year ago #

    Hey Kegan,

    Thanks for the direction, I tried that out while I was doing some testing but wasn't displaying the "Next post in category" link in any of the individual posts. (Only two posts out of 26 are in category 58)

    Any other ideas?

  4. Kegan Quimby
    Member
    Posted 1 year ago #

    hmm... try using a 0?

    <?php next_post_link('%link', 'Next post in category', 0, '58'); ?>

  5. sdjentertainment
    Member
    Posted 1 year ago #

    Does the same thing, any other suggestions?

  6. Kegan Quimby
    Member
    Posted 1 year ago #

    what are your categories?

  7. sdjentertainment
    Member
    Posted 1 year ago #

    They are set up through a custom taxonomy (project_categories) for a custom post type (projects). All the categories are used for sorting different projects so things like

    Design
    Digital
    Event
    Identity
    Illustration
    Installation
    Mobile
    Motion Graphics
    Print
    etc.

    But nothing that conflicts with the reserved terms of WP.

  8. Kegan Quimby
    Member
    Posted 1 year ago #

    everything is in the loop, correct?

  9. sdjentertainment
    Member
    Posted 1 year ago #

    yep

  10. Kegan Quimby
    Member
    Posted 1 year ago #

    try using it with no parameters...

    <?php next_post_link(); ?>

  11. sdjentertainment
    Member
    Posted 1 year ago #

    yeah, I did that in my initial testing, and it spits out the next post title as a link and everything works as expected. It's just when I get to the 3rd and 4th paramater that things start disappearing.

    appreciating the help

Topic Closed

This topic has been closed to new replies.

About this Topic