sql query from multiple meta keys and sort?
-
Hi, I’ve been trying to figure this out for a while:
So I have a bunch of posts with variable amount of custom fields like so:
Post | key1 | key2 | key3
1 | X | we | er
2 | X | | df
3 | Y | xc |some posts don’t have values for every key.
I want to a SELECT statement that finds all posts with key1:X, and then sort these posts alphabetically based on their meta values of key2/key3.
I have something like this so far:
SELECT DISTINCT wp_posts.*
FROM wp_postmeta, wp_posts
WHERE wp_posts.ID = wp_postmeta.post_id
AND wp_postmeta.meta_value = ‘X’
ORDER BY wp_postmeta.meta_valueThis does select all correct posts (the ones where key1:X) but sorts them in some kind of other order (it’s not random, and it’s consistent, but I don’t know what this order is – not alphabetically though).
What am I missing?? Any help would be greatly appreciated!
- The topic ‘sql query from multiple meta keys and sort?’ is closed to new replies.