我试图有条件地将参数馈送到wordpress循环中,因此希望根据过滤器系统提供的标记、类别或属性添加到参数中。
然而,我似乎不知道如何使用$arg将tax\\u查询添加到参数中=
例如,我想更改以下代码:
if ($value[\'priceRange\'] == 0 && $value[\'tags\'] == 0 && !$value[\'type\']) {
if(!$value[\'priceRange\']) {
$value[\'priceRange\'] = array(0,1000000);
}
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => -1,
);
}
if ($value[\'priceRange\'] == 0 && $value[\'tags\'] != 0 && !$value[\'type\']) {
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'product_tag\',
\'field\' => \'slug\',
\'terms\' => $value[\'tags\'],
),
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
\'terms\' => $value[\'tags\'],
),
array(
\'taxonomy\' => \'pa_branding\',
\'field\' => \'slug\',
\'terms\' => $value[\'tags\'],
),
),
);
}
为此:
if ($value[\'priceRange\'] == 0 && $value[\'tags\'] == 0 && !$value[\'type\']) {
if(!$value[\'priceRange\']) {
$value[\'priceRange\'] = array(0,1000000);
}
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => -1,
);
}
if ($value[\'priceRange\'] == 0 && $value[\'tags\'] != 0 && !$value[\'type\']) {
$args .=
\'tax_query\' => array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'product_tag\',
\'field\' => \'slug\',
\'terms\' => $value[\'tags\'],
),
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
\'terms\' => $value[\'tags\'],
),
array(
\'taxonomy\' => \'pa_branding\',
\'field\' => \'slug\',
\'terms\' => $value[\'tags\'],
),
),
);
}
稍后,我还计划在此基础上添加一个针对价格的条件meta\\u查询。
有人有什么建议吗?
提前感谢!