I am attempting to display the latest x posts from all categories using a custom taxonomy called 'case-studies' in WordPress.
I have managed to output all the category names as heading links I have also outputted some posts from the standard posts taxonomy which are in the correct categories, but I can't get this to display anything from my 'case-studies' taxonomy. When I add 'post_type' => 'case-studies'
to $post_args
query it does not show any results.
if (have_posts()) :
$tax = 'case-studies';
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_terms($tax, $cat_args);
foreach($categories as $category) {
echo '<p><a href="' . get_term_link( $category, $tax ) . '" title="'
. sprintf( __( "View all posts in %s" ), $category->name ) . '" '
. '>' . $category->name.'</a></p>';
$post_args = array(
'posts_per_page' => 10,
'category_name' => $category->name
);
$posts = get_posts($post_args);
foreach($posts as $post) { ?>
<a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a><br/>
<?php }
echo '<p><a href="' . get_term_link( $category, $tax ) . '" title="'
. sprintf( __( "View all posts in %s" ), $category->name ) . '" '
. '>View all posts in ' . $category->name.'</a></p>';
}
endif;