WordPress SQL Custom Query To Get Post, Post Meta Data, Category and Featured Image of the post.

I’ve tried so far the below code and got the post and post meta data. Now taxonomy and featured image remaining:

$query = mysql_query("SELECT wp_posts.ID,wp_posts.post_title,   mt1.meta_value as latitude, mt2.meta_value as longitude, mt3.meta_value as full_adddress
FROM wp_posts
LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key='lv_listing_lat')
LEFT JOIN wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id AND mt2.meta_key='lv_listing_lng')
LEFT JOIN wp_postmeta AS mt3 ON (wp_posts.ID = mt3.post_id AND mt3.meta_key='_address')
WHERE wp_posts.post_type = 'lv_listing'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
AND ((mt1.meta_key = 'lv_listing_lat') OR (mt2.meta_key = 'lv_listing_lng' ) OR (mt3.meta_key = '_address' ))
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC ");

Read more here: WordPress SQL Custom Query


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: