您可以使用SQL
global $wpdb;
// For single record
$wpdb->get_row("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = $param1 AND meta_value = $param2");
// For multiple records
$wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = $param1 AND meta_value = $param2" );
将此用于查询
$args = array(
\'posts_per_page\' => 10, // -1 for all posts
\'meta_query\' => array(
array(
\'key\' => \'your_meta_key\',
\'value\' => \'your_meta_value\',
\'compare\' => \'=\',
)
)
);
$the_query = new WP_Query($args);
// The Loop
if ( $the_query->have_posts() ) {
echo \'<ul>\';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
}
echo \'</ul>\';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}