get_the_category return empty inside loop
Question
I’m creating a custom template for my website and I’m currently using this code in order to loop to my multisite worpress and get the latest posts:
global $post;
global $wp_query;
$subsites = get_sites();
foreach( $subsites as $subsite ) {
$subsite_id = get_object_vars($subsite)["blog_id"];
$subsite_name = get_blog_details($subsite_id)->blogname;
switch_to_blog($subsite_id);
$blog_posts = get_posts();
restore_current_blog();
foreach( $blog_posts as $post ) {
setup_postdata( $post );
get_template_part( 'theme-partials/post-templates/loop-content/masonry' );
}
}
Inside the template_part the theme is trying to get the category for the post but return an empty array.
if ( pixelgrade_option( 'blog_show_categories' ) ) {
$categories = get_the_category();
if ( ! is_wp_error( $categories ) && ! empty( $categories ) ) { ?>
How could I get the category information inside the loop?
What’s wrong in my code?
0
categories, get-posts, multisite
4 years
2020-03-27T12:51:22-05:00
2020-03-27T12:51:22-05:00 0 Answers
106 views
0
Leave an answer