Get Latest Post In WordPress (Tiny PHP Code)

Here’s a useful code snippet in PHP for WordPress to get a link to the newest (latest, freshest… you get the idea) post in WordPress.

Code starts here:

$latest = get_posts(array('numberposts' => 1));
$url = get_permalink($latest[0]->ID);
echo "<a href='" . $url . "'>Click here and read our latest post!</a>";

Yeah, that’s it. Have a great day!

Published by

Webmaster

I'm a guy, born and raised in Scandinavia, around 40 years old and have worked self-employed as a webmaster in lots of different fields, niches, doing all kind of work online.