0

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?

1

easy 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.