我再次需要一些帮助。
我使用此查询:
$tax = get_the_terms($id, \'coupon_category\');
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
query_posts( array(
\'post_type\' => APP_POST_TYPE,
\'post_status\' => \'publish\',
\'posts_per_page\' => 4,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'coupon_category\', // Taxonomy
\'field\' => \'slug\',
\'terms\' => $tax[0]->slug, // Your category slug
),
array(
\'taxonomy\' => APP_TAX_STORE,
\'field\' => \'slug\',
\'terms\' => $term->slug,
\'operator\' => \'NOT IN\',
),
),
) );
我知道需要一个解决方案,只显示每个分类术语中的一篇文章
APP_TAX_STORE
. 尝试了一些来自这个userfull论坛的解决方案,但对我来说不起作用。
SO网友:Mohsin Ghouri
是的,当然。
<?php
$included_post_ids =array();
$args = array(
\'post_type\' => \'APP_POST_TYPE\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'coupon_category\', // Taxonomy
\'field\' => \'slug\',
\'terms\' => $tax[0]->slug, // Your category slug
),
),
);
$custom_posts = get_posts( $args );
if( !empty( $custom_posts ) ){
foreach ($custom_posts as $key => $postObj) {
$included_post_ids[] = $postObj->ID;
}
}
//Similar proceduce for other taxonomies
$args = array(
\'post__in\' => $included_post_ids,
\'post_type\' => \'APP_POST_TYPE\',
)
$final_posts = new WP_Query( $args );
if ( $final_posts->have_posts() ) {
}
?>