Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按标题和元数据搜索查询参数_Php_Search_Wordpress - Fatal编程技术网

Php 按标题和元数据搜索查询参数

Php 按标题和元数据搜索查询参数,php,search,wordpress,Php,Search,Wordpress,请帮助我创建按标题和元搜索的查询参数, 示例: 项目: 1-标题:公司,内容:asdf,元字段\供应商:asd 2-标题:公司,内容:公司,,元字段\供应商:asd 3-标题:ttcmp,内容:asdf,元字段\供应商:asd 4-标题:myrus,内容:asdf,元字段\供应商:公司 我的搜索字符串?s=公司 我想搜索的结果是项目:1,2,4 这是qyuery arg $args['wp_query'] = array( 'post_type' => $post_type,

请帮助我创建按标题和元搜索的查询参数, 示例:
项目:
1-标题:公司,内容:asdf,元字段\供应商:asd
2-标题:公司,内容:公司,,元字段\供应商:asd
3-标题:ttcmp,内容:asdf,元字段\供应商:asd
4-标题:myrus,内容:asdf,元字段\供应商:公司 我的搜索字符串?s=公司

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

这是qyuery arg

$args['wp_query'] = array(
    'post_type' => $post_type,
    'posts_per_page' => 5,
    's' => $search_s,
);
$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'
        )
    )
);
结果1和2

这是qyuery arg

$args['wp_query'] = array(
    'post_type' => $post_type,
    'posts_per_page' => 5,
    's' => $search_s,
);
$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.
        ),
    ),
);

我采纳了你的建议,效果很好。非常感谢。这意味着两者之间有一个“AND”:很遗憾,只能返回标题和元键中带有
$search\s
的帖子