Display custom multi-select fields
-
Hi
I have added some custom fields using the Field Editor which was easy enough. I have also been able to display a Single Select field adding the following code in the content-single-event-listing.php override file:<?php echo "Difficulty Level: "; echo get_post_meta(get_the_ID(),'_difficulty_level',true); ?>
However I have a Multi-Select Field which holds multiple selected values about a Dog, such as Playful or Friendly. The meta Key is ‘_temperament_of_dog’. Example of the placeholder values: friendly:Friendly |playful : Playful|energentic : Energentic
When I use the following code, it returns ‘Array‘ on the page rather than the actual values. Code:
<?php echo "Temperament of dogs: "; echo get_post_meta(get_the_ID(),'_temperament_of_dog',true); ?>
I found some code online which suggests a for loop is needed. Code:
$temperament = (array) get_post_meta( $post->ID, '_temperament_of_dog', true ); foreach( $temperament as $temp){ echo $temp['value'];} ?>
When I use the above code it seems to display the first letter of each selected value. So if Playful and Friendly is chosen, it displays as ‘PF’. Also I put [‘value’] as I wasn’t sure what this would be and was trying differnt things.
Can someone help and explain how to display a multi-select list of values. I have no experience of PHP and find altering code quite tricky without proper guidance to follow.
Thanks.
- The topic ‘Display custom multi-select fields’ is closed to new replies.