Wordpress - How do I get the current edit page ID in the admin?
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;
var_dump($id);
}
}
add_action( 'admin_notices', 'id_WPSE_114111' );
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.
<?php
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');
?>