duan0424 2018-07-10 17:18
浏览 38

根据wp_postmeta表中的元数据选择帖子

How do I select a post by its metadata found in the wp_postmeta table? Preferably using ElasticPress.

new WP_Query( array(
    's'             => 'meta search phrase',
    'search_fields' => array(
        'post_title',
        'post_content',
        'post_excerpt',
        'meta' => array( 'meta_key_1', 'meta_key_2' ),
    ),

) );

I found this example from the ElasticPress documentation, but I am not sure that this is querying the correct table (wp_postmeta), and I also want to check if a particular value is in post meta value, not the post meta key...

EDIT:

I've tried this below, but am not getting anything returned with this query. I'm setting 'key' => 'foo_listing_syndication', and 'value' => $term, where $term is the search text and foo_listing_syndication is the key in the meta_key column of the wp_postmeta table. Would this not be correct? See screenshot of the wp_postmeta table. The $term I am trying to search for is found the in meta_value column.

$query = new \WP_Query([
     ...
    's'             => $term,
    'meta_query' => array(
        array(
            'key'   => 'foo_listing_syndication',
            'value' => $term,
            'compare' => '=',
        ),
     ),
]);

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器