Support » Fixing WordPress » How to get Page Id using PHP
8 years, 8 months ago
Anyone know how I can get the page ID using a php function?
8 years, 3 months ago
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
$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$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.
8 years ago
I had been looking for this for ages! Thanks valendesigns!
7 years, 11 months ago
You rock… perfectly what i needed.
7 years, 9 months ago
Using built in stuff:
This provides the entire page record. $page->ID is the id