I am trying to display some meta_values and meta_keys of found post_ids from wp_postmeta table and the post_title of this ID from wp_posts table. Firstly I have to find post_ids (it could be more than one) from given meta_key and meta_value. Than I have to retrieve other meta_values and meta_keys related to post_ids in a table. I have managed to retrieve post_ids with below code;
$meta_key = "wcum_users_id";
$meta_value = "2";
$posts = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = '$meta_key' AND meta_value = '$meta_value' ");
foreach ( $posts as $post ){
$id = $post->post_id;
echo $id;
And it shows;
3873
3797
for example. Then I add the below code inside foreach;
$the_query = new WP_Query( array( 'post_id' => '$id', 'post_type' => 'custom' ) );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
and it results;
3783
trl2000
hgld2015
3797
trl2000
hgld2015
But I need a structure like that;
Title | meta_key1 | meta_key2 | meta_key3
$post_id1 | meta_value11 | meta_value12 | meta_value13
$post_id2 | meta_value21 | meta_value22 | meta_value23
Is it possible?