Hi i have a problem to create an sql query request. I have a working query to get published or private posts on category and a custom post-type and a meta_key 'mapcoordinates' in my wp_usermeta table on user_id. What i try to accomplished is extending the query that I also get another meta_value from my wp_usermeta table with meta_key 'some_value'. So I need to search on two meta_keys values (mapcoordinates , somevalue) instead off one (mapcoordinates), see working example Maybe somebody can help me'
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID, wp_usermeta.meta_value AS user_map_coord, wp_usermeta.user_id
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_usermeta ON ( wp_posts.post_author = wp_usermeta.user_id )
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (5,6))
AND wp_posts.post_type = 'ouder_type'
AND wp_usermeta.meta_key= 'mapcoordinates'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date
Above query is working. I like to extend it in something like this.
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID, wp_usermeta.meta_value AS user_map_coord, wp_usermeta.user_id
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_usermeta ON ( wp_posts.post_author = wp_usermeta.user_id )
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN ( 5,6))
AND wp_posts.post_type = 'ouder_type'
AND wp_usermeta.meta_key= 'mapcoordinates'
// this line added not working i get only one result , expecting 2 results
AND wp_usermeta.meta_key= 'somevalue'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date
AND ( ... OR ...)?