Home › Forums › Add-ons › Repeater Field › get_post_meta for a repeater field › Reply To: get_post_meta for a repeater field
when using get_post_meta()
The field that is your repeater field will return the # of rows in the repeater field.
What you need to get is the meta value of the sub field meta key and the actual key will look something like
{repeater-field-name}_{#}_{sub-field} where {#} is the index of the of the row, starting at 0.
So you need to first get the value from the repeater field, then do a for loop and build the meta_key values and then get each sub field value.
$repeater_value = get_post_meta($post_id, 'repeater_field_name', true);
if ($repeater_value) {
for ($i=0; $i<$repeater_value, $i++) {
$meta_key = 'repeater_field_name_'.$i.'_sub_field_name';
$sub_field_value = get_post_meta($post_id, $meta_key, true);
}
}
what you do from there will depend on what is stored in the sub field.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.