Search query parameters by title and meta

please help me create query parameters for search by title and meta,
example:
item:
1 – title: company, content: asdf, meta_field_vendor: asd
2 – title: comp, content: company, meta_field_vendor: asd
3 – title: ttcmp, content: asdf, meta_field_vendor: asd
4 – title: myrus, content: asdf, meta_field_vendor: company

my search string ?s=company

Read More

I want to search result was items: 1,2,4

This qyuery arg

$args['wp_query'] = array(
    'post_type' => $post_type,
    'posts_per_page' => 5,
    's' => $search_s,
);

result 1 and 2

This qyuery arg

$args['wp_query'] = array(
    'post_type' => $post_type,
    'posts_per_page' => 5,
    'meta_query' => array (
        array(
            'key' => '_item_prop_title',
            'value' => $search_s,
            'compare' => 'EXISTS'
        )
    )
);

result 4

how can I make a query for result 1,3,4?

$args['wp_query'] = array(
    'post_type' => $post_type,
    'posts_per_page' => 5,
    's' => $search_s,
    'meta_query' => array (
        array(
            'key' => '_item_prop_title',
            'value' => $search_s,
            'compare' => 'EXISTS'
        )
    )
);

Cheers!

Related posts

Leave a Reply

2 comments

  1. what you could do for your problem is a dual process of search, if it is not an optimal response but if it works…

     $search_s = 'mykeyword';
    
        $q1 = get_posts(array(
            'post_type' => 'post',
            's' => $search_s
        ));
    
        $q2 = get_posts(array(
                'post_type' => 'post',
                'meta_query' => array(
                    array(
                       'key' => 'my_meta_box',
                       'value' => $search_s,
                       'compare' => 'LIKE'
                    )
                 )
        ));
    
        $merged = array_merge( $q1, $q2 );
    
        $post_ids = array();
        foreach( $merged as $item ) {
            $post_ids[] = $item->ID;
        }
    
        $unique = array_unique($post_ids);
    
        $posts = get_posts(array(
            'post_type' => 'post',
            'post__in' => $unique,
            'post_status' => 'publish',
            'posts_per_page' => -1
        ));
    
        if( $posts ) : foreach( $posts as $post ) :
            setup_postdata($post);
    
            the_title();
    
    
        endforeach; 
        endif;
    
  2. Have you tried something like?:

    $args['wp_query'] = array(
        'post_type' => $post_type,
        'posts_per_page' => 5,
        's' => $search_s,
        'meta_query' => array(
            array(
                'key'       => '_item_prop_title',// Name of the key you want to search. Check your BD to be sure this is the correct name
                'value'     => $search_s,
                'compare'   => 'LIKE',// You can use '=' instead if you want to be more restrictive.
            ),
        ),
    );