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?

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/get_the_category-return-empty-inside-loop/">

get_the_category return empty inside loop</a>
0
, , CrazYoshi 2 months 0 Answers 67 views 0

Leave an answer