I have created a custom post type in Wordpress and created a taxonomy for it. Now I want to display the taxonomy-terms and under each term display the posts that have that term. I'm trying to use get_posts for that, but get-posts just turns up empty. Here is my code with comments on what happens:
<?php
//for each category, show all posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'teachres-categorie',
'post_type'=> 'biology'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => -1,
'category' => array($category->term_taxonomy_id),
'ignore_sticky_posts'=>1,
'post_type'=> 'biology',
'taxonomy' => 'teachres-categorie'
);
?>
<h2><?php echo '<p>Category: <a href="' . get_category_link($category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';?></h2>
<p><?php echo $category->term_taxonomy_id; ?></p>
//this gets displayed just fine, meaning $category-array is filled
<?php
$posts = get_posts($args);
//at this point $args is filled: Array ( [showposts] => -1 [category] => Array ( [0] => 34 ) [ignore_sticky_posts] => 1 [post_type] => biology [taxonomy] => teachres-categorie )
//at this point $posts is empty: Array ( )
if ($posts) {
//This never gets executed as $posts is empty
foreach($posts as $post) {
// ...so we'll never get to here
} // end foreach($posts
} // end if ($posts
} // // end foreach($categories
?>
Other than this code I didn't alter the main post-query and these are the only loops on the page. When I search on this, there are more people with the same problem, but none of their solutions are helpful in my case.
Can anyone tell me why get_posts is empty?