Ok, I have searched and searched through stackoverflow and google and couldn't find what I was looking for. I'm looking for a way to have my next and previous buttons to link to my posts that are in the same post type term.
I have a post type named "Projects" and the taxonomy is "projects_category". I have several terms under that taxonomy and when I'm viewing a single project post, I want to be able to click next and previous within that term. Is there a way to do this?
Update (11/13/13) (again):
This is what I have, now.
<?php
$projectCat = wp_get_post_terms($postid,"projects_category");
if(count($projectCat)){
$projectC = $projectCat[0]->slug;
}
else{
$projectC = "";
}
$args = array(
'post_type'=>'project_post',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'projects_category',
'terms' => '{$projectC}', //define your category id or slug here
'field' => 'slug',
)
),
'order'=>'ASC',
);
$postlist = get_posts($args);
$posts = array();
foreach ($postlist as $post) {
$posts[] += $post->ID;
}
$prev_post = get_previous_post();
$prevID = $prev_post->ID ;
?>
<?php
$next_post = get_next_post();
$nextID = $next_post->ID ;
?>
<?php if (!empty($prevID)) { ?>
<li><a href="<?php echo get_permalink($prevID); ?>"
title="<?php echo get_the_title($prevID) ." ". $projectC; ?>"
class="p_prev widget_anim"><span></span>Previous</a>
</li>
<?php }
if (!empty($nextID)) { ?>
<li><a href="<?php echo get_permalink($nextID); ?>"
title="<?php echo get_the_title($nextID) ." ". $projectC;; ?>"
class="p_next widget_anim">Next<span></span></a>
</li>
<?php }
wp_reset_postdata();
?>
I'm getting the current term that is found on the single-project_post page and the query seems to catch it, but the query is not following that it needs to stay in the term. It's extracting posts from other terms I have. Even if I put the exact term in replace of $projectC in the query, it still gives me the wrong posts for next and previous. Can anyone help me? I appreciate the help so far from the previous answers.