Lego2012
12/13/2016 - 10:49 AM

Get ID from Page Name

Get ID from Page Name

<!-- Add to functions.php file: -->

function get_ID_by_page_name($page_name) {
   global $wpdb;
   $page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_type = 'page'");
   return $page_name_id;
}

<!-- Now you can use this function in templates when you need an ID of a specific post/page and all you have is the name. -->