title: Wordpress SQL query to fetch the meta_key names in a custom post type
body: <p>Using WP dataTables plugin and my MySQL sucks so please bear with me.</p>
  
  <p>I'm trying to fetch multiple associated meta_keys (custom field names) that are allocated to a custom post type in WordPress, and display the fields as the table header with the custom field values in the rows underneath the header.</p>
  
  <p>My SQL below kinda works. While it pulls in a colum called 'meta_key' and 'meta_value', it has the actual names of the key as it's data.  I want the meta_key value itself as the list returned.</p>
  
  <pre><code>SELECT * FROM wp_posts INNER JOIN wp_postmeta 
  ON wp_posts.ID = wp_postmeta.post_id 
  WHERE 1=1 AND wp_posts.post_type = 'my_custom_post' 
  AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') 
  AND (wp_postmeta.meta_key = 'call_date' OR wp_postmeta.meta_key = 'call_time' OR wp_postmeta.meta_key = 'caller_number' OR wp_postmeta.meta_key = 'call_duration' OR wp_postmeta.meta_key = 'call_status' ) 
  ORDER BY wp_posts.menu_order, wp_posts.post_date DESC LIMIT
  </code></pre>
  
  <p>So this creates a table with the header as 'meta_key' but I want the custom field name itself as the header.  Hope this makes sense.</p>
  
  <p>PS I've also tried </p>
  
  <pre><code>SELECT caller_number, call_duration, call_status, call_date, call_time
  FROM wp_posts
  WHERE post_type =  'my_custom_post'
  AND post_status =  'publish'
  FROM wp_postmeta
  WHERE post_id = post_id
  </code></pre>
  
  <p>But it shows no data...</p>
  
  <p>Seriously, any help here would be awesome.</p>