duskosobic
1/25/2017 - 2:53 PM

Get ID from Page Name. Add this to functions.php file and you can use this function in templates when you need an ID of a specific post/page

Get ID from Page Name. Add this to functions.php file and you can use this function in templates when you need an ID of a specific post/page and all you have is the name.

<?php

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;
}

?>