我想在库存中显示(特色产品),但此查询只显示库存产品。
$query = array(
\'post_type\' => \'product\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 12,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'_stock_status\',
\'value\' => \'instock\',
),
array(
\'taxonomy\' => \'product_visibility\',
\'field\' => \'name\',
\'terms\' => \'featured\',
),
),
);
最合适的回答,由SO网友:Buttered_Toast 整理而成
您混合了元查询和税务查询
应该是这样的
$query = array(
\'post_type\' => \'product\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 12,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'meta_query\' => array(
array(
\'key\' => \'_stock_status\',
\'value\' => \'instock\'
)
),
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_visibility\',
\'field\' => \'name\',
\'terms\' => \'featured\'
)
)
);