WordPress - Get Post or Page ID By Name


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.