您可以使用get_the_category
这可以通过使用setup_postdata( $comment_author_post )
或者通过使用$comment_author_post->ID
USING setup_postdata()
$args = array(
\'post_type\' => array( \'post\' ),
\'post_status\' => array( \'publish\' ),
\'author\' => $comment->user_id,
\'orderby\' => \'post_date\',
\'order\' => \'ASC\',
\'posts_per_page\' => 1
);
$comment_author_posts = get_posts( $args );
if ($comment_author_posts):
foreach ( $comment_author_posts as $comment_author_post ):
setup_postdata( $comment_author_post );
$categories = get_the_category();
?>
<a href="<?php echo get_permalink( $comment_author_post->ID ) ?>"><i class="fa fa-users" aria-hidden="true"></i>
<?php echo esc_html( $categories[0]->name ); ?></a>
<?php
endforeach;
endif;
USING $comment_author_post->ID
$args = array(
\'post_type\' => array( \'post\' ),
\'post_status\' => array( \'publish\' ),
\'author\' => $comment->user_id,
\'orderby\' => \'post_date\',
\'order\' => \'ASC\',
\'posts_per_page\' => 1
);
$comment_author_posts = get_posts( $args );
if ($comment_author_posts):
foreach ( $comment_author_posts as $comment_author_post ):
$categories = get_the_category( $comment_author_post->ID );
?>
<a href="<?php echo get_permalink( $comment_author_post->ID ) ?>"><i class="fa fa-users" aria-hidden="true"></i>
<?php echo esc_html( $categories[0]->name ); ?></a>
<?php
endforeach;
endif;
References
get_posts()
get_the_category()