function bir_show_custom_field_translated($post_id, $key, $label = "", $html4label = "", $html4custom_field = "", $single = true, $separator = ",", $other = FALSE, $breakline = FALSE) { /* $key - identification of the custom field Samples for $html4label and $html4custom_field. Keep always the strings "label" and "custom_field", because the function will replace them using regular expression. $html4label "<li>label</li>" "<dt>label</dt>" $html4custom_field "<li>custom_field</li>" "<dd>custom_field</dd>" "<p>custom_field</p>" $separator - character to delimiter a list of words $other - to know if a custom field value set as "Other" should be displayed ot replaced by other content $breakline - content with break line (/n) can be splited. */ $customField = get_post_meta($post_id, $key, $single); if (is_array($customField) or trim($customField) != "") { if ($html4label != "") { $text2show = preg_replace("/label/", $label, $html4label); } else { $text2show = $label; } if (!is_array($customField) and preg_match("/\n/", $customField) and $breakline) { $customField = preg_split("/\n/", $customField); } if (!is_array($customField)) { if ($html4custom_field != "") { $text2show .= preg_replace("/custom_field/", bir_translate_custom_field_values($customField, $other), $html4custom_field); } else { $text2show .= bir_translate_custom_field_values($customField, $other); } } else { $count = count($customField); $lastValue = end($customField); $text = ""; foreach ($customField as $value) { $text .= bir_translate_custom_field_values(trim($value), $other); if ($value != $lastValue) { $text .= $separator . " "; } } if ($html4custom_field != "") { $text2show .= preg_replace("/custom_field/", $text, $html4custom_field); } else { $text2show .= $text; } } } return $text2show; }
<div class="search-strategy-data"> <?php $terms = wp_get_post_terms(get_the_ID(), 'status'); ?> <h4><?php the_title(); ?> </h4> <?php if ($terms) { switch ($terms[0]->name) { case "In review": echo '<span class="in_review">' . bir_translate_custom_field_values($terms[0]->name) . '</span>'; break; case "Reviewed": echo '<span class="reviewed">' . bir_translate_custom_field_values($terms[0]->name) . '</span>'; break; default: break; } } $custom_field_keys = array("description_of_the_search", "main_subject_of_the_search", "secondary_subject_of_the_search"); if (bir_has_no_empty_custom_field(get_the_ID(), $custom_field_keys)) { echo "<h5>"; echo "<i class='about'></i>"; _e('About the search', 'refnet'); echo "</h5>"; } ?> <dl> <?php