首页 > 解决方案 > Wordpress 搜索代码在本地主机上工作,但不在实时环境中

问题描述

我是一名业余的自学成才的 wordpress 开发人员。我实际上正在研究我的第二个自定义主题。

在这个特定的主题中,我有一个搜索表单,可以使用多个自定义字段从自定义帖子类型“个人资料”中进行搜索。

我在 WordPress 搜索页面上有这段代码。

$search = $_GET['s'];

$pre_meta_query = array(
    'relation' => 'OR',
        array(
            'key'     => 'profileName',
            'value'   => $search,
            'compare' => 'LIKE'
        ),
        array(
            'key'     => 'profileServices',
            'value'   => $search,
            'compare' => 'LIKE'
        ),
        array(
            'key'     => 'profileBio',
            'value'   => $search,
            'compare' => 'LIKE'
        ),
        array(
            'key'     => 'profileLocation',
            'value'   => $search,
            'compare' => 'LIKE'
        ),
        array(
            'key'     => 'profileBusinessTel',
            'value'   => $search,
            'compare' => 'LIKE'
        ),
);


//A Basic
$args = array(
    'posts_per_page' => - 1,
    'orderby'        => 'rand',
    'order'          => 'ASC',
    'post_type'      => 'profile',
    'post_status'    => 'publish',
    /*'exact'       => false,
    's'           => $search,
    'sentence'       => true,*/
    'meta_query'     => $pre_meta_query
);

$query         = new WP_Query( $args );
$profiles      = $query->posts;

它适用于我的 xampp 安装而不是实时安装环境。当我检查错误日志时,我收到以下错误:

'ads_postmeta' for query SELECT   ads_posts.*
FROM ads_posts
INNER JOIN ads_postmeta ON ( ads_posts.ID = ads_postmeta.post_id )
INNER JOIN ads_postmeta ON (ads_posts.ID = ads_postmeta.post_id)
WHERE 1=1
AND (
  ( ads_postmeta.meta_key = 'profileName' AND ads_postmeta.meta_value LIKE '%umo%' ) 
  OR 
  ( ads_postmeta.meta_key = 'profileServices' AND ads_postmeta.meta_value LIKE '%umo%' ) 
  OR 
  ( ads_postmeta.meta_key = 'profileBio' AND ads_postmeta.meta_value LIKE '%umo%' ) 
  OR 
  ( ads_postmeta.meta_key = 'profileLocation' AND ads_postmeta.meta_value LIKE '%umo%' ) 
  OR 
  ( ads_postmeta.meta_key = 'profileBusinessTel' AND ads_postmeta.meta_value LIKE '%umo%' )
) AND ads_posts.post_type = 'profile' AND ((ads_posts.post_status = 'publish')) 
GROUP BY ads_posts.IDads_posts.ID ORDER BY RAND() 
made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/classifieds/search.php'), WP_Query->__construct, WP_Query->query, WP_Query->get_posts

最好的解决方案是什么?

标签: wordpresswordpress-theminginner-join

解决方案


推荐阅读