Hi there,
You’ll have to write something like this to make a loop query for your recent post:
https://wordpress.stackexchange.com/posts/35612/revisions
The same code transformed as a shortcode [recent_post]
add_shortcode( 'recent_post', function() {?>
<div id="posts">
<?php
// define query arguments
$args = array(
'posts_per_page' => 5, // your 'x' goes here
'nopaging' => true
// possibly more arguments here
);
// set up new query
$tyler_query = new WP_Query( $args );
// loop through found posts
while ( $tyler_query->have_posts() ) : $tyler_query->the_post();
echo '<section class="post">'.
'<h2><a href="'.
get_permalink().
'">'.
get_the_title().
'</a></h2><p>'.
get_the_excerpt().
'</p></section>';
endwhile;
// reset post data
wp_reset_postdata();
?>
</div>
<?php } );
This is a rough sample. You can refine it to your preference.
Check the parameters for the $args here: https://developer.wordpress.org/reference/classes/wp_query/