我有一个woocomemce网站,产品有“制造商”属性。
当我获得单个产品的条款时:
$terms= get_the_terms($product->id,"pa_manufacturer");
我得到:
Array ( [230] => stdClass Object ( [term_id] => 230 [name] => Dadawan [slug] => dadawan [term_group] => 0 [term_taxonomy_id] => 230 [taxonomy] => pa_manufacturer [description] => [parent] => 0 [count] => 4 [object_id] => 2905 ) )
我是否可以使用该term_id进行循环WP_query以获得具有相同制造商的产品? 我怎样才能获得具有特定term_id的产品?
这是我的测试,但没有工作......
$args = array(
'post_type' => 'product',
'term_id' => 230 ,
'posts_per_page' => 2,
'orderby' => $orderby
);
$loop = new WP_Query( $args );
// Do stuff here to display your products
感谢任何帮助,谢谢。
答案 0 :(得分:2)
您的问题出在您的查询中。对于WP_Query,Term_id不可用。这是一个可用参数列表。我从http://phporlando.com/wp_query-argument-list/
获得了列表attachment attachment_id author author_name cat category__and category__in category__not_in category_name comments_popup day error feed hour minute monthnum name order orderby page_id page paged pagename post__in post__not_in post_status post_type preview robots sentence second static subpost subpost_id tag__and tag__in tag__not_in tag_id tag_slug__and tag_slug__in tag taxonomy - (pre 3.1) tb term - (pre 3.1) w withcomments withoutcomments year Pre WP 3.1 meta_key meta_value Since WP 3.1 fields meta_query tax_query