I currently am using the following code to get a list of posts, showing post_name, post_content and post_id, where there is a custom field (meta_key) used named MediaLink.
SELECT wp_posts.post_name, wp_posts.post_content, wp_posts.ID
FROM wp_posts, wp_postmeta
WHERE wp_posts.ID = wp_postmeta.post_id
AND wp_postmeta.meta_key = "MediaLink"
Here is a visual example of my current table from that query:
post_name | post_content | post_id |
Name 1 Content 1 1
Name 2 Content 2 2
I would like to have the following table:
post_name | post_content | post_id | Artist | Producer
Name 1 Content 1 1 Madonna Philip
Name 2 Content 2 2 Prince Jack
The problem is that Artist & Producer is currently in the wp_postmeta table as :
meta_key | meta_value | post_id | meta_id |
___________________________________________
Artist Madonna 1 1
Artist Prince 2 2
Producer Philip 1 3
Producer Jack 2 4
What do I add to my initial query to to first query to accomplish this?
I want to show the producer and Artist column for post rows that both do and don't have the Artist and Producer fields filled out yet.
This way I can export this data to CSV with PhpMyAdmin and update thousands of posts, affecting all the fields I need per post in one go.