我有一个用于自定义帖子类型数据的简单 WordPress WP 查询循环。由于使用 FacetWP 过滤数据,我必须删除wp_reset_postdata()
. 否则 ajax 过滤不起作用。
但如果我删除,WordPress 会在我的 HTML 内容wp_reset_postdata()
中添加很多p
和标签。br
为什么?
我的代码:
// WP_Query args
$args = array(
'posts_per_page' => 20,
'order' => 'ASC',
'orderby' => 'title',
'ignore_sticky_posts' => true,
'post_type' => 'abc',
'facetwp' => true
);
// The Query
$abc_query = new \WP_Query($args);
// The Loop
if ( $abc_query->have_posts() ) {
while ( $abc_query->have_posts() ) {
$abc_query->the_post();
?>
<div id="abc-wrapper">
<ul class="abc-list">
<li class="abc-list-elem">
<h4 class="abc-title">
<?php the_title(); ?>
</h4>
<span class="abc-desc">
<?php the_content(); ?>
</span>
<?php
$terms = get_the_terms(get_the_ID(), 'abc_types');
foreach($terms as $t) {
?>
<span class="abc-badge">
<?php echo $t->name ?>
</span>
<?php
}
?>
</li>
</ul>
</div>
<?php
}
} else {
// There are no posts
}
}
如果我不使用 重置 postdata,p
您知道为什么 WordPress 会添加很多标签吗?br
wp_reset_postdata()