admin管理员组文章数量:1387386
I use this to search product by name on 2 categories:
<ul class="products">
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
// Request is empty, view all products based url cat ID
if($tmp == '')
{
$args = array(
'post_type' => 'product',
's' => $tmp,
'posts_per_page' => '8',
'paged' => $paged,
'author' => $store_user->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $product_cat_id,
),
)
);
}
else // search all product on categorie 18 & 25
{
$args = array(
'post_type' => 'product',
's' => $tmp,
'posts_per_page' => '8',
'paged' => $paged,
'author' => $store_user->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 18,
),
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 25,
),
),
)
);
}
$loop = new WP_Query( $args );
//var_dump($loop);
if ( $loop->have_posts() )
{}
How can I add query args to see products of brand too ?
Because when I write brand name in search field no product are found.
Thanks
I use this to search product by name on 2 categories:
<ul class="products">
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
// Request is empty, view all products based url cat ID
if($tmp == '')
{
$args = array(
'post_type' => 'product',
's' => $tmp,
'posts_per_page' => '8',
'paged' => $paged,
'author' => $store_user->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $product_cat_id,
),
)
);
}
else // search all product on categorie 18 & 25
{
$args = array(
'post_type' => 'product',
's' => $tmp,
'posts_per_page' => '8',
'paged' => $paged,
'author' => $store_user->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 18,
),
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 25,
),
),
)
);
}
$loop = new WP_Query( $args );
//var_dump($loop);
if ( $loop->have_posts() )
{}
How can I add query args to see products of brand too ?
Because when I write brand name in search field no product are found.
Thanks
Share Improve this question asked Apr 17, 2020 at 18:43 ilanbilanb 933 silver badges12 bronze badges1 Answer
Reset to default 2Founded:
$filter_group_a = array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 18,
),
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => 25,
),
);
$filter_group_b = array(
array(
'taxonomy' => 'product_brand',
'field' => 'description',
'value' => $tmp,
),
);
$args = array(
'post_type' => 'product',
's' => $tmp,
'posts_per_page' => '8',
'paged' => $paged,
'author' => $store_user->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'relation' => 'OR',
$filter_group_a,
$filter_group_b,
),
)
);
}
本文标签: wp querySearch product by brand name in wpquery
版权声明:本文标题:wp query - Search product by brand name in wp_query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744557200a2612547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论