【问题标题】:Sphinx Wordpress plugin narrow results by custom meta_keySphinx Wordpress 插件通过自定义 meta_key 缩小结果
【发布时间】:2014-12-13 04:50:47
【问题描述】:

我正在尝试仅显示具有自定义元密钥“my_metakey”的帖子的结果,该字段也不应该为空。

我尝试修改 sphinx.conf 文件中的 sql_query,但没有成功。

我不熟悉 sphinx 使用 sphinx.conf 文件的方式,所以不确定需要进行多少次编辑才能实现这一点。

我使用的插件是https://wordpress.org/plugins/wordpress-sphinx-plugin/

任何帮助都是高度恰当的!

【问题讨论】:

  • 更改sql_query后,需要重建索引。你用索引器重建了吗?

标签: php sql wordpress sphinx custom-post-type


【解决方案1】:

经过大量测试,我通过修改 sphinx.conf 文件中源 {prefix}main_posts{} 的 SQL 查询,完成了我想要的工作,如下所示:

sql_query        = select \
        p.ID*2+1 as ID, \
        0 as comment_ID,\
        p.ID as post_ID,\
        p.post_title as title, \
        p.post_content as body, \
        t.name as category, \
        my_metakey_meta.meta_value as my_metakey, \
        .
        .
        .
    from \
        {wp_posts} as p \
    left join \
        {wp_term_relationships} tr on (p.ID = tr.object_id) \
        .
        .
    left join \
        wp_postmeta my_metakey_meta on (p.ID = my_metakey_meta.post_id and my_metakey_meta.meta_key = 'my_metakey') \
        .
        .
        .
    where \
        p.id>=$start AND p.id<=$end and \
        p.post_status = 'publish' and \
        my_metakey_meta.meta_value != '' \
        group by p.ID

并修改source {prefix}main_cmets{}的SQL查询如下:

sql_query        = select \
        .
        .
        '' as category, \
        '' as my_metakey, \
        .
        .
        .

【讨论】:

    猜你喜欢
    • 2021-06-13
    • 1970-01-01
    • 2017-11-25
    • 2014-07-24
    • 2015-08-11
    • 1970-01-01
    • 2015-10-03
    • 2011-07-21
    • 2016-03-22
    相关资源
    最近更新 更多