Get previous post for custom post type and custom field

In my custom post type template in my child theme single-brands.php I have:

<?php $prevPost = get_previous_post(true);
if($prevPost) {
$args = array(
‘posts_per_page’ => 1,
‘post_type’ => ‘brands’,
‘meta_key’ => ‘br_type’,
‘meta_value’ => ‘Fashion’,
‘include’ => $prevPost->ID
);
$prevPost = get_posts($args);
foreach ($prevPost as $post) {
setup_postdata($post);
?>

<div id=”apostnav” class=”kfocon”><a class=”aplink” href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”></div>

<?php
wp_reset_postdata();
} //end foreach
} // end if

However, no results are being displayed. I have also tried the filter without the post_type and meta_key and still not getting any results.

I am trying to get the link to the previous custom post type, so I can create back and forth navigation between my custom post types.

Read more here:: Get previous post for custom post type and custom field

Leave a Reply

Your email address will not be published. Required fields are marked *