2021-01-29

Looking to loop through ACF subfields to get label and value without using field_name

I'm looking for an easy way to display prepack sizing distribution for wholesale clothing. So, the product page will display a table with how many pieces of that clothing come in each size. Unfortunately, since I'm new here, I can't upload a picture of my ACF fields but I have an ACF group field and then inside that I have subfields with the size's name(Small, Medium, Large, etc.) and then the value is the number of pieces in that size.

I want to loop through the subfields and echo out the label of the subfield and the value of the subfield so that I can make a table. I don't want to have to use specific subfield names because I want the code to work even if I make changes to the names. Here's what I have so far:

$fields = get_field('lettered_packing'); //my parent field
foreach ($fields as $field) {
    echo $field;
}

Doing this echoes out the value of each subfield but I would also like to be able to echo out the label of each subfield as well. Is this possible?



from Recent Questions - Stack Overflow https://ift.tt/3iTy0MJ
https://ift.tt/eA8V8J

No comments:

Post a Comment