I created many field groups and used ‘Show this field group if.. Page is equal to.. X‘ with the famous Advanced Custom Fields (ACF) plugin.
I’m using get_post_custom_keys()
to show all the custom fields from a page:
$custom_field_keys = get_post_custom_keys(45);
I hardcoded the ’45’ which is not the page ID, but the Field Group ID. I’m struggling to get the ID of the field group associated with the page.
get_post_custom_keys($post_id);
will show the custom fields for the page and not the field group.
I understand there might be multiple field groups associated with one page.
Here is my solution. I look into the database directly and look for any ACF rules for the current page, and grab that ID.
Since ACF 5.0 you can use this function.