1

I am using the following functions in my single.php file to display links to Previous and Next posts:

get_next_post();
get_previous_post();

I store them in 2 variables:

$next_post = get_next_post();
$prev_post = get_previous_post();

and outputting them at the bottom of the page using get_permalink:

$next_post_url = get_permalink( $next_post->ID );
<a href="<?php echo $next_post_url; ?>"> Next </a>

and

$prev_post_url = get_permalink( $prev_post->ID );
<a href="<?php echo $prev_post_url; ?>"> Previous </a>

It does work fine and gives me the "previous" and "next" posts However, it includes all the posts in my blog including all post formats: gallery, images, quote, aside etc etc

Id like to exclude them from being included in the loop because they don't have content. their only purpose in my blog is to show quote or image or something else but the only "content" post which is important is the standard post format

Anyone knows how to accomplish that using my code? (preferably) or different code is better

Thanks

2
  • To stop this (it includes all the posts) from happening you need to make different category for posts that are need to show in pagination. Then in loop you can show only that category of posts. Lets assume your post's category ID is 5. Use 'cat'=> 5 in your array.
    – Rishabh
    Oct 6, 2016 at 5:09
  • Thanks @Rishabh but that I know. I am looking for a better way without having to add category there must be a way to filter post formats Thanks
    – gil hamer
    Oct 6, 2016 at 7:02

1 Answer 1

0
previous_post_link(
                '<div class="text-center video-text-btn"> %link </div> ', 
                'pre', 
                $in_same_term = true, 
                $excluded_terms = 'Standard-post-format-name', 
                $taxonomy = 'post_format'
            );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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