On my home page, I’m trying to loop through a set number of posts and display the category name of each post. The category that I’m trying to display the name for is a subcategory of a parent (if that makes any difference). Here’s my code for it:
<?php
$args = array( 'numberposts' => '15' );
$recent_posts = wp_get_recent_posts( $args );
foreach ( $recent_posts as $recent ) {
$category = get_the_category($recent['ID']);
echo $category['cat-name'];
}; ?>
When I run that, nothing ends up displaying. That page displays as if the code wasn’t there. But when I do a var_dump on $category:
<?php
$args = array( 'numberposts' => '15' );
$recent_posts = wp_get_recent_posts( $args );
foreach ( $recent_posts as $recent ) {
$category = get_the_category($recent['ID']);
echo var_dump($category);
}; ?>
I can see that everything is there that I need. Each post, with it’s keys and values, but for some reason trying to display a specific property of a post (like ‘cat-name’, or even ‘name’) doesn’t work. Any ideas?