WordPress.org

Ready to get started?Download WordPress

Forums

Retrieving the post ID from a permalink (5 posts)

  1. Konstantin Kovshenin
    Member
    Posted 5 years ago #

    Hey everybody.

    Is there by any chance a function that could return the post ID having only the permalink to that post?

    Thanks

  2. asechrest
    Member
    Posted 5 years ago #

    Well, if you're NOT using pretty permalinks, then I believe the permalink actually contains the post ID. In which case you could probably use standard regex to isolate and store the ID in a variable.

  3. Konstantin Kovshenin
    Member
    Posted 5 years ago #

    Nevermind, I found the function. It's called url_to_postid() in rewrite.php

    Thanks!

  4. asechrest
    Member
    Posted 5 years ago #

    Interesting function. Nice find. Some random Googling brings up stuff (mostly old stuff) that indicates the function might be kind of touchy. Let us know how it works. :)

  5. Konstantin Kovshenin
    Member
    Posted 5 years ago #

    Works fine. It's used by the wordpress core when permalinks are enabled, so everything's okay :)

Topic Closed

This topic has been closed to new replies.

About this Topic