SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta

You can do something like

  • Query the wp_posts table
  • Left join the source_name from wp_posmeta table
  • Left join the coverage_url from wp_posmeta table

Then select the data you want to pull from post, source_name and coverage_url result

Something like this should do

SELECT 
    post.ID, 
    post.post_title, 
    sn.meta_value as source_name, 
    cu.meta_value as coverage_url

FROM wp_posts as post

LEFT JOIN wp_postmeta as sn
    ON  post.ID = sn.post_id
    AND sn.meta_key = 'source_name'

LEFT JOIN wp_postmeta as cu
    ON  post.ID = cu.post_id
    AND cu.meta_key = 'coverage_url'

WHERE post.post_type="media_coverage"

You Query output should be somethng like

---- ID ----+---- post_title ----+---- source_name ----+---- coverage_url
-------------------------------------------------------------------------
   1        |     Title Here     |   Source Name Here  |  Coverage URL Here