PHP code: Permalink/URL to the latest/newest post in WordPress.

Here’s a little useful sample to get a link to the newest(latest, freshest… you get the idea) post in WordPress.

Here is the tiny but useful bit of code:

$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!

Leave a Reply

Your email address will not be published. Required fields are marked *