【发布时间】:2015-07-03 12:48:56
【问题描述】:
如何在“帖子编辑”页面中添加一些自定义 PHP,并在帖子发布时获得post_id?
喜欢这个红色区域:
【问题讨论】:
标签: php wordpress wordpress-theming
如何在“帖子编辑”页面中添加一些自定义 PHP,并在帖子发布时获得post_id?
喜欢这个红色区域:
【问题讨论】:
标签: php wordpress wordpress-theming
您可以使用 get_current_screen() 函数 (Link to codex) 来检查您是否在帖子编辑页面上,然后使用全局 $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
}
}
【讨论】:
add_meta_box,它可以按预期工作。不过还是谢谢!周末愉快。