Support

Account

Home Forums Add-ons Repeater Field Understanding the relationship between repeating fields and database entries

Solving

Understanding the relationship between repeating fields and database entries

  • The repeating field type has an awful lot of records in the postmeta WordPress table. Does anyone have a list of those records and what they contain. Here is how it currently seems to me.

    1. A Repeating Field has to have a Field Group, so there is a record that creates the field group.

    2. A Repeating Field has to have a parent name and be attached to the field group. Is this one record or two?

    3. A Repeating Field has child field names which have to be attached to the parent name. Is each one of these one record or two?

    4. Each of the child fields have data. Are these one record or two?

  • A field group is a post in the CPT acf-field-group

    A field is a post in the CPT acf-field. The parent post of this post it acf-field-group post that it is attached to.

    Every field has 2 entries in the db, assuming the field name “field”
    There is an entry with the meta_key “field” that contains the data and an entry with the meta_key “_field” and this contains the field key reference for this field.

    For a repeater field the entry for “field” is the number of rows in the repeater.

    Each sub field of each row has its own 2 entries. The meta key for each sub field is
    “{repeater_field_name}_{row_index}_{sub_field_name}” which has a corresponding field key reference stored at “_{repeater_field_name}_{row_index}_{sub_field_name}”

  • Thank you for the helpful information!

    Regarding “For a repeater field the entry for “field” is the number of rows in the repeater.”

    1. Since a field group, and hence a repeater field, may be used for various posts with different data in each post, is the number the total of all posts or the total applied to a single post?

    2. What is the benefit of storing a count in the database, as opposed to using a counting loop?

    Thanks!

  • 1. it is the number or rows for the post.

    2. Internally ACF does use a loop, the number stored is the number of time to execute the loop. Picture something like this:

    
    $repeater_name = 'repeater';
    $count = intval(get_post_meta($post_id, $repeater, true);
    for ($i=0; $<$count; $i++) {
      $sub_field_value = get_post_meta($post_id, $repeater.'_'.$i.'_sub_field_name');
    }
    

    Without having a count of rows ACF would have no idea how many rows there are. The number of rows must be stored.

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

You must be logged in to reply to this topic.