Home Forums General Issues display list of values from one field group


display list of values from one field group

  • Hi everyone,

    Like in the title. How can I make a list of all values from one field group?
    Ex. group name is “stuff”. There is one field “kind_stuff” (repeater) with some sub_fields like: “name”, “cost”, “photo”, “link”, etc.

    I want to display it in one table. Can anybody help with that?


  • Hi @bispawel,

    The important thing here is the repeater aspect, as opposed to the group itself. So within your post/page you’ll have a repeater that contains say 10 rows of data. It works a little bit like the WordPress loop. First, you check to see if there’s any data at all, then if there is data, you start a while loop to be able to access each repeater row individually.

    Because these are sub_fields you need to use get_sub_field() or the_sub_field() to reference that data. In practice, it should look a little bit like this:

    // check if the repeater field has rows of data
    if( have_rows('kind_stuff') ):
     	// loop through the rows of data
        while ( have_rows('kind_stuff') ) : the_row();
        	// attribute sub fields to variables
        	$stuff_name = get_sub_field('name');
        	$stuff_cost = get_sub_field('cost');
        	$stuff_photo = get_sub_field('photo');
        	$stuff_link = get_sub_field('link');
        		<td><img src="<?php echo $stuff_photo['url']; ?>" alt="<?php echo $stuff_photo['alt']; ?>" /></td>
        		<td><?php echo $stuff_name; ?></td>
        		<td><?php echo "$" . $stuff_cost; ?></td>
        		<td><a href="<?php echo $stuff_link; ?>">View product</a></td>
        <?php endwhile; ?>
    else :
        // no rows found

    Depending on how you’ve set up each of those sub_fields will depend on specifically how you echo them out.

    edit: The Repeater documentation page may help you further:

  • Hi Edd,
    thanks so much! Thats work great. But what if I want display all values? Witch are all in a different post/page or these values are in one category ex. “store”?


  • Assuming i follow your meaning, you’d have to also wrap that snippet of code above with a WP_Query or query_posts call for all the posts that have table data. This could be quite simple if they’re all in one category or of a particular post type, otherwise you may need to get more specific with a meta query, which will allow you to specifically call in all posts that have the photo sub_field filled in, for example.

    If you can give me an idea of the specific heirarchy of the site setup or what the post type is called or the category name I can try to help with your specific query

  • This may be a bit flakey as i’m typing on a phone, but perhaps something like the following:

    $query_store_args = array(
        'post_type' => 'posts',
        'cat' => 'store',
        'posts_per_page' => -1
    $query_store = new WP_Query($query_store_args);
    if( $query_store->have_posts() ) :
        while( $query_store->have_posts() ) : $query_store->the_post();
    // code I added above 

    Edit: forgot a line

  • Yes yes yes…! 🙂
    This is what I need – Edd You are great ! :]

    thanks so much

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

The topic ‘display list of values from one field group’ is closed to new replies.