无需设置新查询,只需使用第一个查询即可。替换:
$loop = new WP_Query( $args2 );
while ( $loop->have_posts() ) {
$loop->the_post();
。。。使用:
$firstloop->rewind_posts();
while ( $firstloop->have_posts() ) {
$firstloop->the_post();
更新:代码中遗漏了一些其他错误,下面是完整的返工:
function new_function() {
$args = array(
\'post_type\' => \'tabs\',
\'posts_per_page\' => 10,
);
$result = \'<div id="tabs">\';
$result .= \'<ul>\';
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) {
$loop->the_post();
$result .= \'<li><a href="#\' . get_the_title() . \'">\' . get_the_title() . \'</a></li>\';
}
$result .= \'</ul>\';
$result .= \'<div id="tabs-container">\';
$loop->rewind_posts();
while ( $loop->have_posts() ) {
$loop->the_post();
$result .= \'<div class="col-md-12">\';
$result .= \'<div class="quote-content"><blockquote>\' . get_the_content() . \'</blockquote></div>\';
$result .= \'<div class="quote-author"><p>\' . get_the_title() . \'</p></div>\';
$result .= \'</div>\';
}
$result .= \'</div>\';
$result .= \'</div>\';
return $result;
}