Php 发布帖子时,将数据添加到帖子编辑页面

Php 发布帖子时,将数据添加到帖子编辑页面,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,发布文章时,如何向“post edit”页面添加一些自定义PHP,并获取post\u id 喜欢这个红色区域: 您可以使用get\u current\u screen()函数()检查您是否在帖子编辑页面上,然后使用全局$post变量获取帖子id 例如: add_action('admin_notices', 'screen_info'); function screen_info() { $screen = get_current_screen(); if(is_admin() &

发布文章时,如何向“post edit”页面添加一些自定义PHP,并获取
post\u id

喜欢这个红色区域:

您可以使用
get\u current\u screen()
函数()检查您是否在帖子编辑页面上,然后使用全局
$post
变量获取帖子id

例如:

add_action('admin_notices', 'screen_info');
function screen_info() {
  $screen = get_current_screen();
  if(is_admin() && $screen->id == 'post') {
    global $post;
    $post_id = get_the_ID();
    // your code here
  }
}

谢谢我发现我可以使用
添加元数据框
,它可以按预期工作。不过还是要谢谢你!有一个愉快的周末。