Php WordPress自定义分类WP\u查询
我正在尝试创建一个查询,其中我在自定义帖子类型中创建了多个类别(分类法),然后在主页上根据具体的内容进行查询,这样做很好。目前我有3种分类法:Php WordPress自定义分类WP\u查询,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我正在尝试创建一个查询,其中我在自定义帖子类型中创建了多个类别(分类法),然后在主页上根据具体的内容进行查询,这样做很好。目前我有3种分类法: 当前特价商品 梅内克差异 特色 我已经编写了拉动这些的代码。我遇到的问题是,在主页上,当这些帖子也附加到“特色”分类法时,它只需要拉这些帖子。因此,这方面的标准逻辑示例如下: 如果分类法=当前特价商品和特色商品,则成功或失败 但它所做的是把它们全部拉出来,因为当前的代码是或,我需要和 想法?(代码如下) 您可以尝试此操作(tax-使用分类法slug。从版
您可以尝试此操作(tax
-使用分类法slug。从版本3.1起已弃用,支持“tax\u query”)
给了我一个空白屏幕。我准确地复制了您的$args数组。
<?php
$post_type = 'coupons';
$tax = 'coupons_category';
$tax_terms = get_terms($tax);
if ($tax_terms):
foreach ($tax_terms as $tax_term):
echo '<div id="'.$tax_term->slug.'" class="coupon-box '.$tax_term->slug.'">';
$args = array(
'post_type' => $post_type,
"$tax" => array($tax_term->slug, 'featured'),
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1
);
$myQuery = null;
$myQuery = new WP_Query($args);
if($myQuery->have_posts()):
while ($myQuery->have_posts()) : $myQuery->the_post();
$price = get_field('price_image', $myQuery->ID);
$print = get_field('print', $myQuery->ID);
$product = get_field('product_box_image', $myQuery->ID);
$title = get_the_title();
$content = get_the_content();
echo '<div class="fourty9 left box center">';
echo '<h1>'.$title.'</h1>';
echo '<p class="center"><img src="'.$price.'" /></p>';
echo '<p>'.$content.'</p>';
echo '<p class="center"><a href="'.$print.'">Print Coupon</a></p>';
echo '<p class="center"><img src="'.$product.'" alt="Filter"></p>';
echo '</div>';
endwhile;
endif;
echo '</div>';
wp_reset_query();
endforeach;
endif;
?>
$args = array(
'post_type' => 'coupons',
'posts_per_page' => -1,
'caller_get_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => 'coupons_category',
'field' => 'slug',
'terms' => array( 'current-specials', 'featured' ),
'operator' => 'AND'
)
)
);
$query = new WP_Query( $args );