Query CPT on multiple meta keys and values
-
Hi
I have a custom post type that contains a meta value for closing date and another for location which I would like to query on
My query for getting posts that have a closing date of after today works as intended
SELECT * FROM wpsc_posts INNER JOIN wpsc_postmeta ON ( wpsc_posts.ID = wpsc_postmeta.post_id ) WHERE 1=1 AND ( ( wpsc_postmeta.meta_key = 'closing_date' AND wpsc_postmeta.meta_value >= '20170412' ) ) AND wpsc_posts.post_type = 'the_jobs' AND wpsc_posts.post_status = 'publish' GROUP BY wpsc_posts.ID ORDER BY wpsc_postmeta.meta_value ASCbut how do I add another meta key and value for location such as
SELECT * FROM wpsc_posts INNER JOIN wpsc_postmeta ON ( wpsc_posts.ID = wpsc_postmeta.post_id ) WHERE 1=1 AND ( ( wpsc_postmeta.meta_key = 'closing_date' AND wpsc_postmeta.meta_value >= '20170412' ) ) AND wpsc_posts.post_type = 'the_jobs' AND wpsc_posts.post_status = 'publish' AND ( ( wpsc_postmeta.meta_key = 'job_location' AND wpsc_postmeta.meta_value >= 'over-here' ) ) GROUP BY wpsc_posts.ID ORDER BY wpsc_postmeta.meta_value ASC
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Query CPT on multiple meta keys and values’ is closed to new replies.