How to get the latest URL of my blog?
Meaning, if I want to create a dynamic URL which will automatically redirect to my latest (max id) post?
Any clues?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityeasy to do with get_posts
// search the last post
$posts = get_posts([
"posts_per_page" => 1,
]);
foreach ($posts as $p) {
// display the permalink
echo esc_html(get_permalink($p));
}
documentation of get_posts
:
https://codex.wordpress.org/Function_Reference/get_posts