Curious if anyone has tried filtering content via get_pages using a custom taxonomy. I’ve got a custom post type labeled “clothing” and I’m trying to create a “Previous & Next” navigation by pulling only the “clothing” pieces that have the slug “female” in the “gender” taxonomy.
However, the Previous and Next links are pulling all clothing pieces, including my “mens” pieces.. Anyone have experience with custom taxonomy and get_pages?
<?php
$args = array(
'sort_column' => 'menu_order',
'sort_order' => 'desc',
'post_type' => 'clothing',
'post_status' => 'publish',
'gender'=> 'female'
);
$list = get_pages($args);
$pages = array();
foreach ($list as $page) {
$pages[] += $page->ID;
}
$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<div class="post-nav">
<?php if (!empty($prevID)) { ?>
<a href="?pID=<?php echo $prevID ?>" title="<?php echo get_the_title($prevID); ?>" class="left">« PREVIOUS</a>
<?php }
if (!empty($nextID)) { ?>
<a href="?pID=<?php echo $nextID ?>" title="<?php echo get_the_title($nextID); ?>" class="right">NEXT »</a>
<?php } ?>
</div>
Used your code in conjunction with this post on advance taxonomy querying, and came up with this:
Works for me and it’s pretty freaking awesome… with the advanced taxonomy querying Otto explains, you can really control those next/previous links quite well. I wouldn’t have been able to figure this out without your original code though, so mad props to you and Otto!
I’m going to try and fine tune this even further by auto detecting the terms from the page…
get_the_term_list()
might work.