Help displaying group
- This topic has 5 replies, 2 voices, and was last updated 9 years, 9 months ago by
totalmarc.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
August 1, 2015 at 10:58 PM #1145
totalmarc
ParticipantFirst of all I'm a novice so bear with me please, I need help displaying a group in a template. I set up the metabox with cloneable group which works fine:
$meta_boxes[] = array( 'id' => 'initiatives', 'title' => __( 'Initiatives', 'test' ), 'post_types' => array( 'page' ), 'context' => 'normal', 'priority' => 'high', 'show' => array( 'relation' => 'OR', 'template' => array( 'template-regions-home.php' ), ), 'autosave' => true, 'fields' => array( //Group array( 'id' => 'initiatives_group', 'name' => __( 'Initiatives', 'test' ), 'type' => 'group', // Group type 'clone' => true, // Can be cloned? // List of child fields 'fields' => array( array( 'name' => __( 'Initiative Title', 'test' ), 'id' => 'initiative_title', 'type' => 'text', ), array( 'name' => __( 'Initiative Featured Image', 'test' ), 'id' => "initiative_image", 'type' => 'file_input', ), ) ); return $meta_boxes; }
I'm stuck how to display them in my template in rows like this, can someone please provide a working example based on above how to make this work?:
function initiatives_box() { $group_value = rwmb_meta( 'initiatives_group' ); ?> <div class="the_image"><img src="<?php echo rwmb_meta( 'initiative_image' ); ?>"></div> <div class="the_title"><?php echo rwmb_meta( 'initiative_title' ); ?></div> }
August 2, 2015 at 11:29 AM #1147Anh Tran
KeymasterCan you try this code:
$group_value = rwmb_meta( 'initiatives_group' ); foreach ( $group_value as $row_value ) { echo '<div class="the_image"><img src="' . $row_value['initiative_image'] . '"></div> <div class="the_title">' . $row_value['initiative_title'] . '</div>'; }
August 2, 2015 at 10:52 PM #1153totalmarc
ParticipantWorks great, thanks so much!
August 2, 2015 at 11:26 PM #1154totalmarc
ParticipantIs it possible the return the value of a select_advanced field with multiple => true so it shows multiple page links selected?
I have:
array( 'name' => __( 'Inititavie Links', 'test' ), 'id' => "intiative_links", 'type' => 'post', 'post_type' => 'page', 'field_type' => 'select_advanced', 'multiple' => true, 'placeholder' => __( 'Select an Item', 'test' ), 'query_args' => array( 'post_status' => 'publish', 'posts_per_page' => - 1, ) ),
Is something like this possible?:
$group_value = rwmb_meta( 'initiatives_group' ); foreach ( $group_value as $row_value ) { echo '<div class="the_image"><img src="' . $row_value['initiative_image'] . '"></div> <div class="the_title">' . $row_value['initiative_title'] . '</div> <div class="the_links">' . $row_value['intiative_links'] . '</div>'; }
August 3, 2015 at 6:23 PM #1157Anh Tran
KeymasterYes, it's possible. If you set
multiple
totrue
, then the value of$row_value['intiative_links']
will be an array, you need to loop through it to output the result:$group_value = rwmb_meta( 'initiatives_group' ); foreach ( $group_value as $row_value ) { echo '<div class="the_image"><img src="' . $row_value['initiative_image'] . '"></div> <div class="the_title">' . $row_value['initiative_title'] . '</div>'; echo '<div class="the_links">'; foreach ( $row_value['intiative_links'] as $id ) { echo '<a href="' . get_permalink( $id ) . '">' . get_the_title( $id ) . '</a>'; } echo '</div>'; }
August 3, 2015 at 10:28 PM #1160totalmarc
ParticipantWorks great, much appreciated!
-
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
- The topic ‘Help displaying group’ is closed to new replies.