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);
  • 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 Mar 18 '20 at 13:34
  • In my case save_post hook is not working – Shadow Mar 19 '20 at 5:59

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.