Query the Latest WordPress Posts by Date With WP_Query

Quick Summary

  • A WP_Query sorted by date in DESC order, with posts_per_page 3 and ignore_sticky_posts, returns the three newest published posts.
  • Each post's featured image URL, permalink, date and title print without HTML, and posts lacking a thumbnail fall back to a placeholder path.
  • suppress_filters set to true skips plugin query filters, so remove that line if the results ignore a multilingual or similar plugin.

This snippet queries the three most recent published posts in WordPress, newest first, and outputs each post’s featured image URL, link, date and title. Use it for a latest-posts block in a home page or landing page template when you want full control over the markup.

The values are printed without any HTML around them, so wrap each one in your own markup: the image URL in the src of an <img> tag, the permalink in the href of a link, and so on.

PHP
<?php
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'DESC',
    'ignore_sticky_posts' => 1,
    'suppress_filters' => true,
    'posts_per_page' => 3

);
$loop = new WP_Query($args);
while ($loop->have_posts()):
    $loop->the_post();

    $blg_featured_img = get_the_post_thumbnail_url();
    if (empty($blg_featured_img))
    {
        $blg_featured_img = "/wp-content/uploads/inf-2.jpg";
    }
?>
<?php echo $blg_featured_img; ?>
<?php the_permalink(); ?>
<?php echo get_the_date(); ?>
<?php the_title(); ?>
<?php endwhile; wp_reset_postdata(); ?>

How it works

  • 'orderby' => 'date' with 'order' => 'DESC' sorts posts by publish date, newest first, and posts_per_page limits the list to 3.
  • ignore_sticky_posts stops sticky posts from being moved to the top, so the order is purely by date.
  • suppress_filters set to true skips the filters plugins can use to change the query. Some plugins, multilingual ones for example, depend on them, so remove the line if your results ignore such a plugin.
  • If a post has no featured image, get_the_post_thumbnail_url() returns false and the code falls back to /wp-content/uploads/inf-2.jpg. Replace that path with your own placeholder image.
  • get_the_date() uses the date format set under Settings > General.
  • wp_reset_postdata() restores the main post data after the loop, so the rest of the template works normally.

If you need posts from a specific period rather than the latest ones, WP_Query also accepts a date_query argument, described in the WP_Query reference. When you add the markup, wrapping the image URL in esc_url() is a good habit.

For custom post lists and queries built into your theme, see my WordPress development services.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More