【问题标题】:Add data to post edit page, when post is published发布帖子时将数据添加到帖子编辑页面
【发布时间】:2015-07-03 12:48:56
【问题描述】:

如何在“帖子编辑”页面中添加一些自定义 PHP,并在帖子发布时获得post_id

喜欢这个红色区域:

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    您可以使用 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,它可以按预期工作。不过还是谢谢!周末愉快。
    猜你喜欢
    • 1970-01-01
    • 2017-08-30
    • 2013-05-28
    • 2016-05-24
    • 2018-11-17
    • 1970-01-01
    • 2017-09-20
    • 2020-03-21
    • 1970-01-01
    相关资源
    最近更新 更多