Adding this function will solve the issue (compliments of another poster):
function my_acf_post_id() {
if ( is_admin() && function_exists( 'acf_maybe_get_POST' ) ) :
return intval( acf_maybe_get_POST( 'post_id' ) );
else :
global $post;
return $post->ID;
endif;
}
Adding this function will solve the issue (compliments of another poster):
function my_acf_post_id() {
if ( is_admin() && function_exists( 'acf_maybe_get_POST' ) ) :
return intval( acf_maybe_get_POST( 'post_id' ) );
else :
global $post;
return $post->ID;
endif;
}
They’re stored within the wp_postmeta and wp_posts databases.
Alternatively you can use
get_the_ID();
To pull the post id, which does work when the post is published, but will not actually pull the Post ID for the preview. I’d love to figure out why or what that work-around is though.
It seems that throughout the Gutenberg Blocks, the ID is changed to the Block ID instead of housing the Post ID.
Are you using ACF Pro and have you created templates for your Gutenberg Blocks and called them via: acf_register_block()?
Example:
acf_register_block(array(
'name' => 'accordian',
'title' => __('Accordian'),
'description' => __('A custom accordian block.'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'formatting',
'icon' => 'no',
'keywords' => array( 'testimonial', 'quote' ),
));
You can switch to Edit mode, it’ll be available when you have selected the Block you wish to Preview/Edit. Look for the Edit (Pencil icon) in the main toolbar and click on that. You can click on the Preview (Eye icon) to flip back.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.