按标题和元搜索查询参数


Search query parameters by title and meta

请帮我创建查询参数,以便按标题和元进行搜索,例:
项目:
1 - 标题:公司,内容:ASDF,meta_field_vendor:ASD
2 - 标题:公司,内容:公司,meta_field_vendor:ASD
3 - 标题:TTCMP,内容:ASDF,meta_field_vendor:ASD
4 - 标题:迈鲁斯,内容:ASDF,meta_field_vendor:公司

我的搜索字符串 ?s=公司

我想搜索结果是项目: 1,2,4

这 qyuery arg

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

结果 1 和 2

这 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'
        )
    )
);

结果 4

如何查询结果 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'
        )
    )
);

干杯!

你可以

为你的问题做的是双重搜索过程,如果它不是最佳响应,但如果它有效......

 $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;

你试过类似的东西吗?

$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.
        ),
    ),
);