我试图只发布每个自定义分类法的一篇文章APP_TAX_STORE
我的wp_query
如下所示:
// show all alternative active coupons for this category from related store
$tax = get_the_terms($id, \'coupon_category\');
$args = array(
\'post_type\' => APP_POST_TYPE,
\'post_status\' => \'publish\',
\'posts_per_page\' => 5,
\'meta_key\' => \'clpr_topcoupon\',
APP_TAX_TAG => \'gutschein\',
\'orderby\' => array(
\'meta_value_num\' => \'DESC\',
\'post_date\' => \'DESC\',
),
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'coupon_category\',
\'field\' => \'slug\',
\'terms\' => $tax[0]->slug,
),
array(
\'taxonomy\' => APP_TAX_STORE,
\'field\' => \'slug\',
\'terms\' => $term->slug,
\'operator\' => \'NOT IN\',
),
),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) :
$query->the_post();
get_template_part( \'loop\', \'coupon\' );
endwhile;
wp_reset_postdata();
现在我需要告诉循环只显示每个帖子的一个帖子
APP_TAX_STORE
(分类学)。
我知道我可能需要第二个查询,然后必须进行组合。然而,我在这个论坛上尝试了太多的解决方案,我完全不知所措。
有了这个问题,我可以给每个APP_TAX_STORE
$terms = get_terms(array(\'taxonomy\' => APP_TAX_STORE));
foreach ($terms as $term){
$args = array(
\'post_type\' => APP_POST_TYPE,
\'posts_per_page\' => \'1\',
\'order_by\' => \'date\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => APP_TAX_STORE,
\'field\' => \'slug\',
\'terms\' => $term->slug,
)
)
);
$new_query = new WP_Query ($args);
if ($new_query->have_posts()) {
while($new_query->have_posts()){
$new_query->the_post();
get_template_part( \'loop\', \'coupon\' );
}
}
}
现在我需要把这些结合起来!
非常感谢您的帮助!
SO网友:mrben522
假设所有常数都是正确的,它应该是这样的
$terms = get_terms(array(\'taxonomy\' => APP_TAX_STORE));
$tax = get_the_terms($id, \'coupon_category\');
foreach ($terms as $term) {
$args = array(
\'post_type\' => APP_POST_TYPE,
\'posts_per_page\' => \'1\',
APP_TAX_TAG => \'gutschein\',
\'orderby\' => array(
\'meta_value_num\' => \'DESC\',
\'post_date\' => \'DESC\',
),
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'coupon_category\',
\'field\' => \'slug\',
\'terms\' => $tax[0]->slug,
),
array(
\'taxonomy\' => APP_TAX_STORE,
\'field\' => \'slug\',
\'terms\' => $term->slug,
),
)
);
$new_query = new WP_Query ($args);
if ($new_query->have_posts()) {
while ($new_query->have_posts()) {
$new_query->the_post();
get_template_part(\'loop\', \'coupon\');
}
}
}