我正在尝试使用基金会框架创建选项卡,从名为testimonial的自定义post类型中输出帖子,并在下对它们指定的名为filed的自定义类别进行筛选。我的循环有什么不对?
<#>What我有工作
What不工作
Link到演示 http://staging-newmummycompanyca.temp312.kinsta.cloud/testimonials/
代码
';
echo '';
echo 'All';
echo '';
$args = array(
'hide_empty' => 1,
'orderby' => 'name',
'order' => 'ASC',
'post_type' => 'testimonial',
'taxonomy' => 'filed-under',
);
$categories = get_categories($args);
foreach ($categories as $category) {
echo
'
' . $category->name . '
';
}
echo '';
// TABBED CONTENT
echo '';
echo '';
echo '';
foreach ($categories as $category) {
$the_query = new WP_Query(array(
'post_type' => 'testimonial',
'post_status' => 'publish',
'category_name' => $category->slug,
));
while ($the_query->have_posts()) : $the_query->the_post();
echo '';
echo '';
the_title();
echo '';
echo '';
echo the_field('testimonial');
echo '';
echo '';
endwhile;
wp_reset_postdata();
}
echo '';
echo '';
echo '';
?>CODE V2
';
echo '';
echo 'All';
echo '';
$_terms = get_terms(array('filed-under'));
foreach ($_terms as $term) {
// TABBED HEADERS
echo '';
echo '';
echo $term->name;
echo '';
echo '';
} // CLOSE OFF FIRST LOOP
echo '';
foreach ($_terms as $term) :
$term_slug = $term->slug;
// QUERY
$_posts = new WP_Query( array(
'post_type' => 'testimonial',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'filed-under',
'field' => 'slug',
'terms' => $term_slug,
),
),
));
// TABBED CONTENT
echo '';
echo '';
echo '';
if( $_posts->have_posts() ) : while ( $_posts->have_posts() ) : $_posts->the_post();
echo '';
echo '';
echo '';
the_title();
echo '';
echo '';
echo '';
echo the_field('testimonial');
echo '';
echo '';
endwhile; endif; wp_reset_postdata();
echo '';
echo '';
echo '';
endforeach;
?>发布于 2020-11-11 16:37:08
' publish',这是你的问题,一个额外的空间角色。
请注意,将来您可以通过使用Query和检查是否找到posts来捕获它。因为post循环缺少一个if ( $query->have_posts() ) { ... } else { echo "none found"; }类型检查,所以您无法知道在哪里查找问题。
此外,您还在filed-under分类法中列出术语:
'taxonomy' => 'filed-under',但是,您将这些项传递给category_name参数,这是不相关的。因此,现在这些术语被用作分类分类中的术语,但它们不是。
https://wordpress.stackexchange.com/questions/378004
复制相似问题