Displaying meta fields that hold multiple values
-
As the doc states: only the first element of each meta field is displayed when using {META[metafieldname]}
I threw together a very quick , dirty , probably not optimal, not working in every case, … ?? hack that allows me to display my meta field as a comma separated list in case there is more than 1 value.
Around line 336 in plugins/recent-posts-plus/recent-posts-plus.php
there is a line that saysforeach($meta_matches[0] as $key => $meta_match) {
I changed the code in that foreach-loop with the following…
And again : disclaimer ; this is very quick and dirty – don’t have alot of time to think this through for all usecases, I need to get this site finished. you know how it is.foreach($meta_matches[0] as $key => $meta_match) { if(!empty($meta_matches[1][$key])) { $the_metadata = get_post_meta($ID, $meta_matches[1][$key], true); // META field has multiple values. if (is_array($the_metadata)) { foreach ($the_metadata as $element) { $post_id = get_post($element); $title = $post_id->post_title; $widget_ouput_template_params[$meta_match] .= $title . ","; } $widget_ouput_template_params[$meta_match] = trim(rtrim($widget_ouput_template_params[$meta_match]),","); } else { // META field just has ONE value. $widget_ouput_template_params[$meta_match] = $the_metadata; } } else { $widget_ouput_template_params[$meta_match] = ''; } }
- The topic ‘Displaying meta fields that hold multiple values’ is closed to new replies.