Support » Plugin: Advanced Custom Fields: Extended » How to get the Custom meta data

  • Resolved bossion

    (@bossion)


    Hi, I want to know how to get the “Custom meta data” in PHP code,
    I try to used “get_field()” and it’s failed!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I think you’re trying to access the “custom meta data” at the bottom of the field group configuration (displayed at the bottom of the following screenshot).

    Those data are tied to the field group, not to a specific field, that’s why get_field() doesn’t work here.

    If you want to retrieve those data, you will have to use the function acf_get_field_group(). Here is an example:

    
    // Get field group: group_abcdef123456 (you may use the ID too)
    $field_group = acf_get_field_group('group_abcdef123456');
    
    // $field_group = acf_get_field_group(28);
    
    // Print the field group
    echo '<pre>'; print_r($field_group); echo '</pre>';
    
    // Print the field group custom meta data
    echo '<pre>'; print_r($field_group['acfe_meta']); echo '</pre>';
    

    Here is a small helper function that let you get the field group, based on a field:

    
    // Retrieve field group custom meta based on the field 'my_field'
    function my_acf_get_field_group_meta_by_field($field, $post_id = 0){
    
        $field_object = get_field_object($field, $post_id);
        
        if(!$field_object)
            return false;
            
        if(!isset($field_object['parent']) || empty($field_object['parent']))
            return false;
            
        $field_group = acf_get_field_group($field_object['parent']);
        
        if(!$field_group || !isset($field_group['acfe_meta']))
            return false;
            
        return $field_group['acfe_meta'];
        
    }
    
    $field_group_meta = my_acf_get_field_group_meta_by_field('my_field');
    
    // Print the field group custom meta data
    echo '<pre>'; print_r($field_group_meta); echo '</pre>';
    

    I hope it helps 🙂

    Regards.

    Thread Starter bossion

    (@bossion)

    @hwk-fr Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get the Custom meta data’ is closed to new replies.