I have two meta_keys on a custom post type. I want to be able to query all of these posts, and order them by the two meta_key
, one taking precedence over the other.
I.e. I have one meta_key
called stickied
, these should always appear first. The second meta_key
is popularity
, which is a basic hit count for that post.
When I use meta_query
, it seems that posts without the meta keys initialized will not appear in the result set. I want all posts regardless of whether they have the meta_key
initialized or not, and then order them based on those meta_key
.
Is this possible?
INNER JOIN
between thewp_posts
andwp_postsmeta
tables where the IDs matchAND
themeta_key
exists. If youvar_export()
the query you can see it, and theorderby
applied at the end. I suppose you could force apopularity
and/orstickied
default value(s) at post creation though; a0
andfalse
, respectively.