Rookie PHP question sorting custom field result
I use this to pull values from a custom field with multiple values:
<?php $mykey_values = get_post_custom_values('services');
foreach ( $mykey_values as $key => $value ) {
echo "<li> $value</li>";
} ?>
I want to sort the output according to how I have set the values in the key (in alphabetical order)
+2
a source to share
2 answers
$mykey_values = get_post_custom_values('services');
sort($mykey_values, SORT_STRING);
echo "<ul>\n<li>" . implode('</li><li>', $mykey_values) . "</li>\n</ul>";
Documentation for get_post_custom_values()
i sort()
.
0
a source to share