Support

Account

Home Forums General Issues Get Group Subfield Value via Shortcode

Solving

Get Group Subfield Value via Shortcode

  • Hello,

    How can we get a Group Subfield value through a shortcode?

  • Something like this?

    function group_shortcode($atts)
    {
        $group = get_field($atts[0]);
        foreach($group as $key => $value) {
            print_r($value);
        }
    }
    add_shortcode('acf_group', 'group_shortcode');

    then use [acf_group GROUPNAME]

  • I tried to use this, but I don’t understand php enough to figure out what the attribute to use is here. Meaning I have set up the shortcode to be used.
    How would a shortcode look like in content: I tried:
    [acf_group "Group field name"]
    [acf_group field= "Group field name"]
    [acf_group Group field name]

  • 
    [acf field="{$GROUP_FIELD_NAME}_{$SUB_FILED_NAME}"]
    
  • I realize this is an old post, but I know this is exactly what I’m looking for. Unfortunately, I cannot get it to display anything and I think it’s just my syntax that’s wrong.

    Group = “certificates”
    Repeater Field = “certificate_image”
    Subfield = “image_file_1″`

    I want to display the value of “image_file_1”.

    Would I change:

    [acf field="{$GROUP_FIELD_NAME}_{$SUB_FILED_NAME}"]

    to:

    [acf field="{certificates}_{image_file_1}"]

    I’ve been at this since 8:45 this morning and I know this is the last piece that I need. Any and all help is appreciated.

  • In your case you have a repeater inside of a group. To add to this you are trying to get an image field and I don’t think shortcodes will work with image fields, but I’m not sure. In any case you need to use

    
    // acf repeater row indexes start at 0
    [acf field="{$group_field_name}_{$repeater_name}_{$row_index}_{$sub_field_name}"]
    
Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Get Group Subfield Value via Shortcode’ is closed to new replies.