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.