Support

Account

Home Forums Front-end Issues $post->meta_field returning count for repeater field

Solved

$post->meta_field returning count for repeater field

  • So, we can do this –

    ACF text field – has some info – standard ways to access this are
    get_post_meta( $post->ID, ‘text_field’, true );
    or
    get_field( ‘text_field, $post-ID );
    or as of WP 3.5
    $post->text_field

    And this – $post->text_field is so clean. It seems to work great for text, text area, WYSIWYG and even checkboxes ( which are serialized data, so we get a multi dimentional array returned from $post->example_checkboxes ). But for a repeater field, we just get the count. $post->repeater_field // 2, or 3, however many rows we have in it.

    Anyone know a way around this? I tired $post->repeater[0][‘subfield’] but no luck.
    Thanks

  • How is the data saved?

    The repeater field saves all it’s data in the wp_postmeta table. If your repeater field is called “gallery” and contains 2 sub fields called “image” and “description”, this would be the database structure of 2 rows of data:

    // meta_key meta_value

    gallery                      2                 // number of rows
    gallery_0_image              6                 // sub field value
    gallery_0_description        "some text"       // sub field value
    gallery_1_image              7                 // sub field value
    gallery_1_description        "some text"       // sub field value

    that means:
    try this:

    $post->repeater_0_subfield //for first row
    $post->repeater_1_subfield //for second row
    ...

    or create a foreach or a while loop: described here

  • Thanks mediawerk – that works!

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

The topic ‘$post->meta_field returning count for repeater field’ is closed to new replies.