I haven't found a solution to displaying multiple postmeta meta_key/meta_values by SQL query of a post. I am using the Advanced Custom Fields (ACF) plugin on another website and trying to pull the contents of the posts on a secondary website. Everything displays well except it is not able to display more meta_values.
Here is my code:
$mydb = new wpdb('database_name','database_user','database_pw','database_host');
$rows = $mydb->get_results("
SELECT P.ID, P.post_title, P.post_content, P.post_author, meta_value
FROM wp_posts AS P
LEFT JOIN wp_postmeta AS PM on PM.post_id = P.ID
WHERE P.post_type = 'post' and P.post_status = 'publish'
and meta_key = 'job_title'
and meta_key = 'company_email' //2nd meta_key I need to work
ORDER BY P.post_date DESC
");
foreach ($rows as $row) :
echo $row->meta_value;
endforeach;
As you can see, I am able to retrieve just one meta_key/meta_value but have multiple fields to display.