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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

I 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