我做了一个简单的循环来显示类别和品牌的产品库(自定义分类法)
这里是我的循环:
<?php
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 4,
\'orderby\' => \'DESC\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'brands\',
\'field\' => \'id\',
\'terms\' => array($category)
),
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'id\',
\'terms\' => array($category)
)
),
);
$wp_query = null;
$wp_query = new WP_Query( $args );?>
但没什么可展示的。当我改变时
\'relation\' => \'AND\', to \'relation\' => \'OR\',
仅按品牌展示的产品。
Practice with the following Nitin Singh Chouhan\'S code and Champeau\'s suggestion, but still failed
<?php
$args = array(
\'post_type\' => array(\'post\',\'product\'),
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'product_cat\',
\'terms\' => array($category),
\'field\' => \'id\'
),
array(
\'taxonomy\' => \'brands\',
\'terms\' => array($categories_brands),
\'field\' => \'id\'
),
)
);
);
$wp_query = null;
$wp_query = new WP_Query( $args );?>
<?php if ( $wp_query -> have_posts()) : ?>
<?php while ( $wp_query -> have_posts()) : $wp_query -> the_post(); ?>
<?php the_title(); ?>
<?php
endwhile;
wp_reset_query();
endif;
?>
有人能帮我吗?
谢谢你的帮助。