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);
  • This is not the only way. You can use get_page_by_path(). The “slug” is without domain.

  • Reddit Monopoly

    Where do you put this? $ID = url_to_postid(slug);