最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Is there any way to get post meta from publish_post hook?

programmeradmin0浏览0评论

I want a post meta of the published post, below is the code but I didn't get it. Appreciate if anyone can help me here:

class BarrioBlog {
    function __construct() {
      add_action( 'publish_post', array( $this, 'on_publish_post' ), 10, 2 );
    }
    function on_publish_post($post_id, $post) {
       echo ' custom field: ' . get_field('channel', $post_id);
       exit;
    }
}

I want a post meta of the published post, below is the code but I didn't get it. Appreciate if anyone can help me here:

class BarrioBlog {
    function __construct() {
      add_action( 'publish_post', array( $this, 'on_publish_post' ), 10, 2 );
    }
    function on_publish_post($post_id, $post) {
       echo ' custom field: ' . get_field('channel', $post_id);
       exit;
    }
}
Share Improve this question asked Mar 18, 2020 at 13:15 ShadowShadow 685 bronze badges 2
  • Have you tried the save_post hook instead? It fires multiple times, but if you use that hook and check whether $_POST contains any data, and only do your action when it does, you'll have access to all the postmeta. – WebElaine Commented Mar 18, 2020 at 13:34
  • In my case save_post hook is not working – Shadow Commented Mar 19, 2020 at 5:59
Add a comment  | 

1 Answer 1

Reset to default 0

Okay so it was resolved with do_action( 'acf/save_post', $post_id );

发布评论

评论列表(0)

  1. 暂无评论