How to get the Field Group ID from a page using ACF and Wordress?

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:

Read More

$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.

Related posts

Leave a Reply

2 comments

  1. Here is my solution. I look into the database directly and look for any ACF rules for the current page, and grab that ID.

    //Look for ACF rules for the current post
    $rows = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = 'rule'");
      foreach ($rows as $row) {
        $values = unserialize($row->meta_value);                            
        if ($postid == $values["value"]) { $numberofacffield = $row->post_id; }
    }
    
    //Then read fields for the acf group id : $numberofacffield 
    $custom_field_keys = get_post_custom_keys($numberofacffield);