Tagged: add_more
- This topic has 2 replies, 2 voices, and was last updated 6 years, 11 months ago by
Gregg.
-
AuthorPosts
-
-
February 25, 2015 at 1:40 pm #3362
GreggMemberHi Steve
I couldn’t find a solution on the forum for this. I have a simple group field that has two fields that include drop-down select options. When running the Piklist function to retrieve the content it’s returning keys instead of values for the drop-down options.
My Meta Box declaration:
piklist('field', array( 'type' => 'group' ,'field' => 'gwfg_accolade_nominations' ,'label' => __('Nominations') ,'add_more' => true ,'fields' => array( array( 'type' => 'select' ,'field' => 'gwfg_accolade_result' ,'label' => 'Result' ,'value' => 'none' ,'columns' => 4 ,'choices' => array( 'none' => '' ,'winner' => 'Winner' ,'runner-up' => 'Runner Up' ,'nominated' => 'Nominated' ,'first-place' => 'First Place' ,'second-place' => 'Second Place' ,'third-place' => 'Third Place' ,'honorable-mention' => 'Honorable Mention' ) ) ,array( 'type' => 'select' ,'field' => 'gwfg_accolade_category' ,'label' => 'Category' ,'value' => 'none' ,'columns' => 4 ,'choices' => array( 'none' => '' ,'best-director' => 'Best Director' ,'best-actor' => 'Best Actor' ,'best-supporting-actor' => 'Best Supporting Actor' ,'best-screenplay' => 'Best Screenplay' ,'best-editing' => 'Best Editing' ) ) ,array( 'type' => 'text' ,'field' => 'gwfg_accolade_name' ,'label' => 'Name' ,'value' => '' ,'columns' => 4 ) ) ));My CPT template code:
<?php $accolade = get_post_meta( $post->ID, 'gwfg_accolade_nominations', true ); ?> <?php piklist( get_stylesheet_directory() . '/accolades-nomination', array('data' => $accolade, 'loop' => 'data')); ?> <?php get_template_part( 'accolades', 'nomination' ); ?>My template part:
<?php $accolade_meta = ''; // Clear the field if( ! empty ( $data['gwfg_accolade_result'] ) ) { $accolade_meta = $data['gwfg_accolade_result']; } if ( ! empty ( $data['gwfg_accolade_category'] ) ) { if ( ! empty( $accolade_meta ) ) { $accolade_meta.='–' . $data['gwfg_accolade_category']; } else { $accolade_meta = $data['gwfg_accolade_category']; } } if ( ! empty ( $data['gwfg_accolade_name'] ) ) { if ( ! empty( $accolade_meta ) ) { $accolade_meta.='–' . $data['gwfg_accolade_name']; } else { $accolade_meta = $data['gwfg_accolade_name']; } } if ( ! empty( $accolade_meta ) ) { echo '<span class=".h5">' .$accolade_meta. '</span>'; } ?>Attachments:
You must be logged in to view attached files. -
February 25, 2015 at 4:55 pm #3365
SteveKeymasterThe keys are what’s stored in the database. Currently there is no way to automatically pull the values.
You will have to write a function to do this.
To make this easier you can place the field or the choices in a separate function and cal it in the admin and front end.
Let me know if that makes sense.
-
February 25, 2015 at 5:21 pm #3366
GreggMemberIt’s not really clear to me why I couldn’t reference the $values of the $keys, but that’s because I’m still wrapping my head around arrays and referencing them correctly.
For the sake of simplicity, I’m making the key and value the same i.e. ,’Best Director’ => ‘Best Director’.
-
-
AuthorPosts
- The topic ‘Group Field Add_More Array Values’ is closed to new replies.