WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Most solutions I found are for front-end use. This is for a plugin, so the all activity is in the back-end.

How do I get the page ID that's being currently use(edited) in the admin?

Note I'm out of the loop. I just need to get the ID of page(not posts) that I'm currently seeing in the back-end.

share|improve this question
You can get it from URL wp-admin/post.php?post=14&action=edit – Bindiya Patoliya Sep 14 '13 at 5:07
I see the URL as a last shot. I hope there is more elegant way to do that. – Daniel Sep 14 '13 at 5:11
up vote 4 down vote accepted

You can also use

$post_id = $_GET['post'];

Or you can use a hook (probably better).

function id_WPSE_114111() {
    global $post;
    $id = $post->ID;
    // do something

add_action( 'admin_notices', 'id_WPSE_114111' );

You will need to add a conditional since this will run on all admin pages, I recommend using get_current_screen();

For example to run only on pages:

function id_WPSE_114111() {

    global $my_admin_page;
    $screen = get_current_screen();

    if ( is_admin() && ($screen->id == 'page') ) {
        global $post;
        $id = $post->ID;

add_action( 'admin_notices', 'id_WPSE_114111' );
share|improve this answer
I need for pages. – Daniel Sep 14 '13 at 5:27
This also works for pages. – Wyck Sep 14 '13 at 5:34

You can add this code in functions.php file and it will give you a meta box above the publish settings box when editing a post or page.


function cf_post_id() {
    global $post;

   // Get the data
   $id = $post->ID;

   // Echo out the field
   echo '<input type="text" name="_id" value="' . $id . '" class="widefat" disabled />';

 function ve_custom_meta_boxes() {
    add_meta_box('projects_refid', 'Post ID', 'cf_post_id', 'post', 'side', 'high');
    add_meta_box('projects_refid', 'Page ID', 'cf_post_id', 'page', 'side', 'high');
   add_action('add_meta_boxes', 've_custom_meta_boxes');

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.