实际上,你不需要拒绝使用while()
环相同的WP\\U Post对象已存储在中post
属性:
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
// some code here if you want.
while ( $query->have_posts() ) {
$query->the_post();
// now $query->post is WP_Post Object, use:
// $query->post->ID, $query->post->post_title, etc.
}
}