I have a custom query which I'm trying to run. How I want it to work is,
Firstly, check the page title
if the page title is the same as the name of the cat from a custom taxonomy then show all the posts that are in that custom taxonomy - post type.
The only trouble is, it isn't returning anything, I've made sure I'm targeting the correct 'post type' & correct 'taxonomy' name. It will return the cat id with the following:
$cat->cat_ID;
But won't return any posts, here is my code:
<?php
// Get the name of the page
$theTitle = get_the_title();
//Get the taxonomy for the custom post type
$categoryselect = array( 'taxonomy' => 'team-members' );
$categories = get_categories($categoryselect);
// loop through each category as cat
foreach ($categories as $cat):
//If cat is the same as title *name* then lets do something
if($theTitle == $cat->cat_name):?>
<h3>We’re here to help.</h3>
<?php
$catID = $cat->cat_ID;
//echo $catID;
//query the posts but, use the cat ID so the page relates to it.
$args = query_posts(array( 'post_type' => 'team', 'cat'=> $catID, 'orderby' => 'title', 'showposts' => -1 ));
$loop = new WP_Query( $args );
// run the loop for posts
while ( $loop->have_posts() ) : $loop->the_post();?>
<div class="person">
<h5><?php the_title(); ?></h5>
</div>
<?php endwhile;
endif;
endforeach;
This is on a page.php template
Any suggestions?