【发布时间】:2018-09-27 16:41:39
【问题描述】:
我正在开发一个插件,该插件将放置在我的 woocommerce 产品侧边栏中。 我需要它,给定产品 ID/对象,它会找到 2 个具有我之前创建的自定义分类的产品。
通过这段代码,我得到了我的产品中使用的术语列表,其中“collane”是自定义分类法:
get_the_term_list( $product->id, 'collane', '<div style="direction:rtl;">', '</div>', '' );
问题是我不知道如何获取自定义分类 id,以及如何通过我的自定义分类对其进行过滤。
我已经使用 WP_Query 用此代码查找同一类别的产品:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $atts['limit'],
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => $cat_id,
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
),
array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => 'exclude-from-catalog', // Possibly 'exclude-from-search' too
'operator' => 'NOT IN'
)
)
);
如何更改我的代码以获得所需的分类 ID/对象,然后在我的 WP_Query 中使用它?
【问题讨论】:
标签: php wordpress woocommerce product custom-taxonomy