UPDATE这是我的最终代码。它工作得很好。
<?php $pageTitle = get_the_title();
// Query Arguments
$args = array (
\'post_type\' => \'car\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'brand_category\',
\'value\' => $pageTitle
),
),
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
echo \'<h3>Cars</h3>
<table style="width: 100%">
<col style="width:35%">
<col style="width:30%">
<col style="width:20%">
<col style="width:15%">
<thead>
<tr>
<th>Name</th>
<th>Style</th>
<th>ABC</th>
<th>Rating</th>
</tr>
</thead>
<tbody>\';
while ( $query->have_posts() ) {
$query->the_post();
echo \'<tr>\';
echo \'<td>\';
echo \'<a href="\'.get_permalink().\'">\'.get_the_title().\'</a>\';
echo \'</td>\';
echo \'<td>\' . get_post_meta( get_the_ID(), \'style\', true) . \'</td>
<td>\' . get_post_meta( get_the_ID(), \'abc\', true) . \'</td>
<td>\' . get_post_meta( get_the_ID(), \'rating\', true). \'</td>
</tr>\';
}
echo \'</tbody>
</table>\';
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
?>