Skip to content

Instantly share code, notes, and snippets.

@gaambo
Created July 29, 2019 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaambo/a504c61c38d645b7efe5ea2f21e7a142 to your computer and use it in GitHub Desktop.
Save gaambo/a504c61c38d645b7efe5ea2f21e7a142 to your computer and use it in GitHub Desktop.
ACF Post Type location rule in block field groups
/**
* Sets the post id from an acf ajax request
* This is needed for the post_type location rule to work on block field groups
*/
add_filter('acf/location/screen', function ($screen) {
$postID = get_the_ID();
if (!$postID) {
$postID = $_REQUEST['post_id'] ?? false;
}
if ($postID && !$screen['post_id']) {
$screen['post_id'] = $postID;
}
return $screen;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment