Support

Account

Home Forums Front-end Issues Getting fields from a field group

Solving

Getting fields from a field group

  • Is there currently a way to output an array for a field group.

    I am using the following code to create name value pairs but I would love to be able to loop through all the values in a give field group.

    $description = get_field_object('space_description');
    $dimensions = get_field_object('space_dimensions');

    Note I can’t do this at a post level since I need to style the groups slightly differently.

  • Hi,

    As far as I’ve understood, you need to get all the key and value of a field group in an array, for that you did the right thing by using get_field_object(). For example, you can print_r('$description') to see whole array and then get the value that you want like: $description['value']['url']

    I hope I have understood you correctly,

  • Thanks @reardestani but this doesn’t solve my question.

    I am already doing what you suggested above; however I would like the array of the entire field group; not each item.

    That is, in your example above when I do

    $description = get_field_object('field_name');
    print_r('$description');
    

    I see this as one of the items in the array [field_group]=>xxx

    I want to be able to loop through an array of all items in that field group and output named pair values

  • Hi @webfliccy

    You can load all fields that have values on the current post by using the get_field_objects.

    If you require fields for a specific field group, you will need to use the core filter to load them as shown in this thread:

    http://support.advancedcustomfields.com/forums/topic/if-statement-based-on-field-type/

    Thanks
    E

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Getting fields from a field group’ is closed to new replies.