php – posts_search中的自定义查询

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – posts_search中的自定义查询脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将此查询用作自定义搜索查询
add_filter('posts_seArch','my_search_is_PErfect',20,2);
function my_search_is_perfect($search,$wp_query) 
{
   $sWord = 'Zukunft haus';

   return "
       SELECT *,MATCH(post_tITle) AGaiNST('$sWord' IN BOOLEAN MODE) AS score 
        From `wp_posts` 
       INNER JOIN wp_term_relationships ON wp_term_relationships.object_id = ID
             AND wp_term_relationships.term_taxonomy_id = 1
       WHERE MATCH( post_title) AGAINST ('$sWord' IN BOOLEAN MODE) 
         AND `post_status` = 'publish'
         AND `post_type` = 'post'
       ORDER BY score DESC
  "; 
}

查询是正确的(我在PHPMyAdmin中检查过)但在wordpress中我得到了消息,没有结果.

在function.PHP文件中:
add_filter('posts_search',2);
function my_search_is_perfect() 
{
    global $post;
    global $wpdb;
    $sWord = 'Zukunft haus';

    $sel_query = "SELECT *,MATCH(post_title) AGAINST('$sWord' IN BOOLEAN MODE) AS score 
                    From ".$wpdb->PRefix."posts 
                   INNER JOIN ".$wpdb->prefix."term_relationships ON ".$wpdb->prefix."term_relationships.object_id = ID
                         AND ".$wpdb->prefix."term_relationships.term_taxonomy_id = 1
                   WHERE MATCH( post_title) AGAINST ('$sWord' IN BOOLEAN MODE) 
                     AND post_status = 'publish'
                     AND post_type = 'post'
                   ORDER BY score DESC";
    $totaldata = $wpdb->get_results($sel_query);

    return $totaldata;
}

脚本宝典总结

以上是脚本宝典为你收集整理的php – posts_search中的自定义查询全部内容,希望文章能够帮你解决php – posts_search中的自定义查询所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。