首先,您应该为这些复杂查询使用WordPress查询对象。这会给你更多的参数。
所以,你可以这样做:
// Let's prepare our query:
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'basePrice',
'compare' => 'EXISTS'
),
)
);
$the_query = new WP_Query($args);
// Array to save our matchs:
$pages = array();
// The Loop
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
// Let's take what we need, here the whole object but you can pick only what you need:
$pages[] = $the_query->the_post();
}
// Reset our postdata:
wp_reset_postdata();
}
这应该只是罚款。
使用get_pages()
的另一种方式是获取所有页面 - >循环它们 - >创建一个get_post_meta()if语句。如果有值,则将当前页面添加到您的阵列。但是,正如你可以想象的,你必须加载所有页面,而你不应该。
希望有帮助,