admin管理员组文章数量:1278853
I am looking to show search results from either product title or product tag name. I have implemented the product title search through the below code, but I need to add tag name search also into it. Please help me with this Wp_query.
Current code :
function iqonic_title_filter( $where, $wp_query ){
global $wpdb;
if( $search_term = $wp_query->get( 'iqonic_title_filter' ) ) :
$search_term = $wpdb->esc_like( $search_term );
$search_term = ' \'%' . $search_term . '%\'';
$title_filter_relation = ( strtoupper( $wp_query->get( 'title_filter_relation' ) ) == 'OR' ? 'OR' : 'AND' );
$where .= ' '.$title_filter_relation.' ' . $wpdb->posts . '.post_title LIKE ' . $search_term ;
endif;
return $where;
}
add_filter( 'posts_where', 'iqonic_title_filter', 10, 2 );
And I am using it as :
$args['iqonic_title_filter'] = $parameters['text'];
I have looked many answers, but none of them seems to work.
I am looking to show search results from either product title or product tag name. I have implemented the product title search through the below code, but I need to add tag name search also into it. Please help me with this Wp_query.
Current code :
function iqonic_title_filter( $where, $wp_query ){
global $wpdb;
if( $search_term = $wp_query->get( 'iqonic_title_filter' ) ) :
$search_term = $wpdb->esc_like( $search_term );
$search_term = ' \'%' . $search_term . '%\'';
$title_filter_relation = ( strtoupper( $wp_query->get( 'title_filter_relation' ) ) == 'OR' ? 'OR' : 'AND' );
$where .= ' '.$title_filter_relation.' ' . $wpdb->posts . '.post_title LIKE ' . $search_term ;
endif;
return $where;
}
add_filter( 'posts_where', 'iqonic_title_filter', 10, 2 );
And I am using it as :
$args['iqonic_title_filter'] = $parameters['text'];
I have looked many answers, but none of them seems to work.
Share Improve this question edited Nov 19, 2021 at 20:40 Dhruvbhati asked Nov 19, 2021 at 17:56 DhruvbhatiDhruvbhati 1113 bronze badges1 Answer
Reset to default 0I solved it by creating 2 different wp query and then merging them. I also excluded the post ids of 1st query in 2 query to avoid duplicate items.
本文标签: wp queryWpquery function to search from producttitle 39OR39 product tags name
版权声明:本文标题:wp query - Wp_query function to search from product_title 'OR' product tags name 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741212641a2359430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论