Home › Forums › General Issues › Custom Fields on post Preview › Reply To: Custom Fields on post Preview
The options doesn’t work with the above fixes. I hooked to the hook in the end and simplified abit and it seems this works all the way: previews, blocks, post acf fields _and_ options:
function fix_acf_field_post_id_on_preview($post_id, $original_post_id)
{
// Don't do anything to options
if (is_string($post_id) && str_contains($post_id, 'option')) {
return $post_id;
}
// Don't do anything to blocks
if (is_string($original_post_id) && str_contains($original_post_id, 'block')) {
return $post_id;
}
// This should only affect on post meta fields
if (is_preview()) {
return get_the_ID();
}
return $post_id;
}
add_filter('acf/validate_post_id', __NAMESPACE__ . '\fix_acf_field_post_id_on_preview', 10, 2);
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.