du5739 2014-12-13 04:50
浏览 66
已采纳

Sphinx Wordpress插件通过自定义meta_key缩小结果

I'm trying to show the results only for posts which has a custom meta_key "my_metakey", the filed also should not be empty.

I've tried to modify the sql_query inside the sphinx.conf file with no luck.

I'm not familiar with the way sphinx uses the sphinx.conf file, so not sure how many edits are required to achieve this.

The plugin I'm using is https://wordpress.org/plugins/wordpress-sphinx-plugin/

Any help is highly appropriated!

  • 写回答

1条回答 默认 最新

  • dsmgcse8876 2015-01-04 10:40
    关注

    After lots of testing I've accomplished what I was looking for by modifying the SQL query of source {prefix}main_posts{} inside the sphinx.conf file as the following:

    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
    

    And modified the SQL query of source {prefix}main_comments{} as the following:

    sql_query        = select \
            .
            .
            '' as category, \
            '' as my_metakey, \
            .
            .
            .
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分