Have a look at the WP_Query codex, they have a range of parameters you can use, and example functions.
First setup your arguments, I have included 2 ways of doing this, the first being the easiest using the built in category parameters.
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 12,
'category_name' => 'x', // Use the category slug.
);
I prefer using the tax_query parameter, as it has given me less problems when using 3rd party plugins.
//Setup your arguments
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 12,
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'x',
),
);
Lastly run the query and loop through it using a while
loop.
//Run the query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<div>
<a href="https://wordpress.stackexchange.com/questions/337796/<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
</div>
<?php
}
wp_reset_postdata();
}