I have a post type called families where I add personal information of each family, inside the data there is an option called status.

*IMPORTANT: The fields are created with ACF CUSTOM FIELDS


These families are shown on one page each. For example

family on site

What I need is to exclude the families that do not have the status Retained, and that are not shown or linked in the next and back buttons.

next an back

in my code I have functions get_next_post_link() and get_previous_post_link()

$older_link = get_next_post_link( '%link', '<i class="far fa-angle-right"></i>' );
$newer_link = get_previous_post_link( '%link', '<i class="far fa-angle-left"></i>' );
$previous = '<span class="meta-nav">Previous Post</span>';
$next = '<span class="meta-nav">Next Post</span>';
<nav class="d-flex align-items-center navigation navigation-single">
    <div class="arrows">
        <?php echo $newer_link; ?>
        <?php echo $older_link; ?>

Thank you very much for your help


What is Status? If it's a taxonomy - and, by the look of it, it should be - you can exclude any given term in get_previous_post_link using the $excluded_terms parameter.

If status is not a taxonomy already, you might want to rethink that for performance reasons.

  • The status is a value I take from a custom field named family_status
    – dexter
    Oct 14 at 19:32
  • i tried this way but don't work $family_id = get_field( 'family_id' ); $status_family = get_field( 'status' ); if ( $status_family !== 'Retained'){ $exclude[] = $family_id; } $newer_link = get_previous_post_link( '%link', '<i class="far fa-angle-left"></i>', false, $exclude ); $older_link = get_next_post_link( '%link', '<i class="far fa-angle-right"></i>', false, $exclude );
    – dexter
    Oct 14 at 19:36

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.