Snippets

Get post ID from slug

“url_to_postid” is the only way to retrieve a post ID from a slug. Just add the entire slug of a post to find the ID.

$ID = url_to_postid(slug);

Share this snippet

 
  • http://www.undolog.com Giovambattista Fazioli

    This is not the only way. You can use get_page_by_path(). The “slug” is without domain.