まず、この種の複雑なクエリには 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();
}
それはうまくいくはずです。
もう 1 つの使用方法get_pages()
は、すべてのページを取得する -> ループする -> get_post_meta() if ステートメントを作成することです。値がある場合は、現在のページを配列に追加します。しかし、ご想像のとおり、すべてのページをロードする必要はありませんが、ロードする必要はありません。
それが役立つことを願って、