This might not be what you’re after but it has proven to be useful for me and some of the advanced things I do with WordPress.
// Get the id of a page by its name
function get_page_id($page_name){
global $wpdb;
$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
return $page_name;
}
If you had a custom query and needed to know the id of a page you could use get_page_id(‘portfolio’) and it would return the id of portfolio.
I had been looking for this for ages! Thanks valendesigns!
You rock… perfectly what i needed.
Using built in stuff:
$page=get_page_by_title($page_name);
This provides the entire page record. $page->ID is the id