Recently I began to use the Custom Fields. I would like to display a listing of posts which contains the meta_key "oldtimer" and also get the corresponding meta_value.
Here is the expected result:
<table>
<tr>
<td>Title of post 1</td>
<td>OLD-39283</td>
</tr>
<tr>
<td>Title of post 2</td>
<td>OLD-22445</td>
</tr>
<tr>
<td>Title of post 3</td>
<td>OLD-32145</td>
</tr></table>
Here is the PHP code I have for now. I don't know how to get the meta_value for each post:
$args =
array(
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title',
'meta_key' => 'oldtimer'
);
$the_query = new WP_Query($args);
// The Loop
if ( $the_query->have_posts() ) {
echo '<table>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<tr><td><a href="'. get_the_permalink() .'">' . get_the_title() . '</td>';
echo '<td>meta_key</td></tr>';
}
echo '</table>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
Here is the information on SQL side:
Is anyone has an idea? Any suggestion about this will be much appreciated.