您可以使用fields
的参数WP_Query
只获取ID,然后使用foreach
回路:
$args = array(
\'post_type\' => \'services\',
\'posts_per_page\' => -1,
\'fields\' => \'ids\',
);
$query = new WP_Query( $args );
if( $query->have_posts() ){
foreach( $query->posts as $id ){
the_field( \'the_field\', $id );
}
} else {
echo \'There are no services\';
}