Posted By

levinet on 09/03/10


php page wordpress name slug id

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


WordPress - Get Post or Page ID By Name

 / Published in: PHP

Returns the post or page id using the name/slug of a page.

  1. function getPageByName($page_name) {
  2. global $wpdb;
  3. $page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
  4. return $page_name_id;
  5. }

Report this snippet  

You need to login to post a comment.