Ordering meta values for WP_Query?
-
Hello!
So I have a problem that I cant seem to find a solution to anywhere here or on other forums.
I have a meta_key lets call it ‘color’ that I am adding to certain posts. Lets say the keys are ‘red’, ‘blue’, ‘yellow’ and ‘green’.
Now I use a custom query to look for those posts with the meta_key ‘color’ using those arguments:
$args = array( 'post_type' => 'project', 'orderby' => 'meta_value', 'meta_key' => 'color');
Now everything works as expected, but my question is how can I SORT the meta_values in a custom order. WordPress just uses them in alphabetical order so blue, green, red, yellow, but I would like to have a custom order so that I first get all posts with yellow, then green, then blue and then red.
Anybody have a solution for that?
Thanks so much!
- The topic ‘Ordering meta values for WP_Query?’ is closed to new replies.