Here is how you can do it. But make sure to change the post_type slug as per your need. In this example I have used gallery_cpt
- Setup a custom query
$args = array(
'post_type' => 'gallery_cpt',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC'
);
$the_query = new WP_Query($args);
2. Loop through the above query and display the results accordingly
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post();
echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
endwhile;
wp_reset_postdata();
else :
echo '<p>No posts found.</p>';
endif;