get post custom keys -and- order by value
-
Hi everyone,
I have succeeded in getting get_post_custom_keys to work in retrieving a list of all the custom keys(names) associated to a post, but I would like to re-arrange the names in output.
WordPress custom fields arranges the names of these fields in alphabetical order and I can’t find a way to make it re-order the output.
For example:
Custom Fields:
Name- Bee Value- 3
Name- Crocodile Value- 2
Name- Dragon Value- 6If this was outputted, using get_post_custom_names, the result would be:
Bee
Crocodile
DragonBut I would like to order the result by value DESC
so my output would be:
Dragon
Bee
CrocodileHere is my code:
<?php $custom_field_keys = get_post_custom_keys(); foreach ( $custom_field_keys as $key => $value ) { $valuet = trim($value); if ( '_' == $valuet{0} ) continue; echo $key . " => " . $value . "<br />"; } ?>
Does anyone know a simple way to alter the code so I can achieve my goal. Thank you for any help
James
- The topic ‘get post custom keys -and- order by value’ is closed to new replies.