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
|
1 Answer
Reset to default 0Okay so it was resolved with do_action( 'acf/save_post', $post_id );
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