Get latest post from categories

Ok you can use a foreach loop to return the latest post from each category.
Here is how you should do that.

<?php

    $postids = array();
    $catids = array( 1, 2, 3 ); // add category ids here.

    foreach ( $catids as $catid ) {

        $my_query = new WP_Query( array( 'cat' => $catid, 'ignore_sticky_posts' => 1, 'posts_per_page' => 1, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false ) );

        if ( $my_query->have_posts() ) :

            while ( $my_query->have_posts() ) : $my_query->the_post();
                $postids[] = $post->ID;
            endwhile;

        endif;

        wp_reset_postdata();

    }

    print_r( $postids ); // printing the array.

?>

It’s practically the same as running the 3 different loops but code is much cleaner now.