您需要在每个while循环之后放置wp\\u reset\\u postdata()。最好的做法是在每个循环之后放置。放置后,您将获得每个自定义帖子类型的图像数据。
<?php
// The Query
$query1 = new WP_Query( $args );
if ( $query1->have_posts() ) {
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
//print post thumbnail
echo get_the_post_thumbnail(get_the_ID(), \'thumbnail\' );
//get post thumb url
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),\'full\');
}
/* Restore original Post Data
* NB: Because we are using new WP_Query we aren\'t stomping on the
* original $wp_query and it does not need to be reset with
* wp_reset_query(). We just need to set the post data back up with
* wp_reset_postdata().
*/
wp_reset_postdata();
}
/* The 2nd Query (without global var) */
$query2 = new WP_Query( $args2 );
if ( $query2->have_posts() ) {
// The 2nd Loop
while ( $query2->have_posts() ) {
$query2->the_post();
//print post thumbnail
echo get_the_post_thumbnail( $query2->post->ID, \'thumbnail\' );
//get post thumb url
$featured_img_url = get_the_post_thumbnail_url($query2->post->ID,\'full\');
echo \'<li>\' . get_the_title( $query2->post->ID ) . \'</li>\';
}
// Restore original Post Data
wp_reset_postdata();
}
?>