如果我理解得当,
您可以使用post__in
用于查询职位ID位于该参数中的特定职位的参数:
$ids = [ 1, 2, 3, 4, 5 ];
$query = new WP_Query( array(
\'post__in\' => $ids,
// ... other args, if any.
) );
// Then loop through the posts.
if ( $query->have_posts() ) {
while ( $query->have_posts() ) : $query->the_post();
the_title();
// ... your code here.
endwhile;
wp_reset_postdata();
}
或者,使用
foreach
具有
setup_postdata()
无需执行
new WP_Query()
:
global $post;
$ids = [ 1, 2, 3, 4, 5 ];
foreach ( $ids as $id ) {
$post = get_post( $id );
setup_postdata( $post );
the_title();
// ... your code here.
}
wp_reset_postdata();