Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Latest post by category

// WP_Query arguments
$args = array(
	'nopaging'               => false,
	'posts_per_page'         => '1',
	'ignore_sticky_posts'    => false,
	'tax_query'              => array(
		array(
			'taxonomy'         => 'category',
			'terms'            => array( '1', ' 2' ),
		),
	),
);

// The Query
$post_by_cat = new WP_Query( $args );

// The Loop
if ( $post_by_cat->have_posts() ) {
	while ( $post_by_cat->have_posts() ) {
		$post_by_cat->the_post();
		// do something
	}
} else {
	// no posts found
}

// Restore original Post Data
wp_reset_postdata();