Wordpress 按自定义属性对象筛选电子商务产品

Wordpress 按自定义属性对象筛选电子商务产品,wordpress,woocommerce,woothemes,Wordpress,Woocommerce,Woothemes,我刚刚继承了一个woocommerce项目,我需要将主页更改为只显示特定品牌。他们建立了一个产品数据=>Attribute=>pa_品牌 如果我打印pa_品牌阵列,它会显示以下内容: Array ( [0] => stdClass Object ( [term_id] => 1134 [name] => Name Brand [slug] => name-brand [term_group] =>

我刚刚继承了一个woocommerce项目,我需要将主页更改为只显示特定品牌。他们建立了一个产品数据=>Attribute=>pa_品牌

如果我打印pa_品牌阵列,它会显示以下内容:

Array
(
[0] => stdClass Object
    (
        [term_id] => 1134
        [name] => Name Brand
        [slug] => name-brand
        [term_group] => 0
        [term_taxonomy_id] => 1134
        [taxonomy] => pa_brand
        [description] => 
        [parent] => 0
        [count] => 68
        [object_id] => 3385
        [filter] => raw
    )
)
我的印象是,我可以使用Pau品牌,使用其中一个键值对过滤查询,最好是slug,但我不确定如何做到这一点。我发现的所有示例都没有对象,只有字符串结果:

$args = array(
'post_type' => array('product', 'product_variation'),
'posts_per_page' => 3,
'orderby' => 'rand',
'meta_query' => array(
    array(
        'key' => 'pa_brand',
        'value' =>  array('slug' => 'brand-name'),
        'compare' => '=',
    ),
    array(
        'key' => '_stock_status',
        'value' => 'instock',
        'compare' => '='
    )
)
))


我试过很多不同的方法,但都不管用。有什么建议吗

商业属性是分类法

假设您要创建品牌属性,url结构如下所示

$args = array( 
    'post_type' => 'product', 
    'taxonomy' => 'pa_brand', // This is the taxonomy slug for brand taxonomy
    'term' => 'honda' // This is terms slug of the Honda Brand
);
yoursite.com/wp admin/edit tags.php?分类法=pa_品牌&post_类型=产品

您可以看到分类名称是
pa_brand

现在,如果你创建了一个品牌,比如本田,在这个分类法下,url是这样的

$args = array( 
    'post_type' => 'product', 
    'taxonomy' => 'pa_brand', // This is the taxonomy slug for brand taxonomy
    'term' => 'honda' // This is terms slug of the Honda Brand
);
yoursite.com/wp admin/edit tags.php?action=edit&taxonomy=pa_brand&tag_ID=6&post_type=product

其中,本田是标签id为6的
pa_品牌分类法下的标签

现在要在特定分类下进行查询

我们可以使用

我们可以用这样的论点

$args = array( 
    'post_type' => 'product', 
    'taxonomy' => 'pa_brand', // This is the taxonomy slug for brand taxonomy
    'term' => 'honda' // This is terms slug of the Honda Brand
);
如果您参考文档,上面的参数与

编辑: Woocommerce属性是分类法,而不是自定义字段

您需要使用
tax\u query
而不是
meta\u query
,分类法保存在
wp\u term\u taxonomy
wp\u terms
数据库表下,而
meta\u query
用于基于
wp\u postETA
数据库表下保存的元字段/自定义字段值的对象查询