Retrieving the post ID from a permalink (5 posts)

  1. Hey everybody.

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


  2. asechrest
    Posted 7 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. Nevermind, I found the function. It's called url_to_postid() in rewrite.php


  4. asechrest
    Posted 7 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. 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