admin管理员组文章数量:1394228
I am trying to make a feed arguments into a wordpress loop conditionally, and hence want to add to arguments based on tags, categories or attributes provided by a filter system.
I can't seem to work out how to add tax_queries to arguments, however, using $arg .=
For example, I want to change the following code from this:
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'],
),
),
);
}
To this:
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'],
),
),
);
}
I later plan to add a conditional meta_query for price onto this also.
Anyone got any pointers?
Thanks in advance!
I am trying to make a feed arguments into a wordpress loop conditionally, and hence want to add to arguments based on tags, categories or attributes provided by a filter system.
I can't seem to work out how to add tax_queries to arguments, however, using $arg .=
For example, I want to change the following code from this:
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'],
),
),
);
}
To this:
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'],
),
),
);
}
I later plan to add a conditional meta_query for price onto this also.
Anyone got any pointers?
Thanks in advance!
Share Improve this question edited Mar 6, 2020 at 20:49 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Mar 6, 2020 at 20:47 parvez noorparvez noor 1514 bronze badges1 Answer
Reset to default 1Try this...
<?php
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' ],
),
);
}
?>
本文标签: wp queryHow to add taxquery to args with concatenation
版权声明:本文标题:wp query - How to add tax_query to $args with concatenation 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744689853a2619927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论