2017-01-23 56 views
0

我想用 自定义字段 可以搜索表 postmeta显示蜱和信息搜索,在本地主机类型的代码,以使搜索形式,但该网站没有加载 我用的是XAMPP 问题是什么?wp_query多个Meta键

这是我的代码

<?php 
$args = array(
    'post_type' => 'house', 
    'meta_query' => array(
     array(
      'key' => 'city', 
      'value' => $_GET["city"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'part', 
      'value' => $_GET["part"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'statuss', 
      'value' => $_GET["statuss"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'typee', 
      'value' => $_GET["typee"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'statuss', 
      'value' => $_GET["statuss"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'rooms', 
      'value' => $_GET["rooms"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'wcss', 
      'value' => $_GET["wcss"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'metr', 
      'value' => $_GET["metr"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'minip', 
      'value' => $_GET["minip"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'maxp', 
      'value' => $_GET["maxp"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'tabaghe', 
      'value' => $_GET["tabaghe"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'rahn', 
      'value' => $_GET["rahn"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'ejareh', 
      'value' => $_GET["ejareh"], 
      'compare' => 'LIKE', 
     ) 
    ) 
); 
$all_posts = new WP_Query($args); 
if ($all_posts->have_posts()) :?> 
    <div class="titSearchHouse" 
     style="text-align: center;width: 150px;margin: 12px auto 0;background: #d0d0d0;color: #FFFFFF;font-family: 'B Yekan';padding: 10px"> 
     display results 
    </div> 
    <div class="parti"> 
     <?php while ($all_posts->have_posts()):$all_posts->the_post(); ?> 
      <!--start post wrapper--> 
      <a class="post-link" href="<?php echo get_the_permalink(); ?>"> 
       <div class="post wow fadeInUp"> 
        <div class="post-inner"> 
         <div class="post-thumb"> 
          <?php echo get_the_post_thumbnail($all_posts->post->ID, 'main-thumbnail'); ?> 
         </div> 
         <span 
          class="post-title"><?php echo get_the_title($all_posts->post->ID); ?></span> 
        </div> 
        <div class="post-meta"> 
                  <span><i 
                    class="fa fa-clock-o"></i><?php echo get_the_date('Y-m-d', $all_posts->post->ID); ?></span> 
         <span><i class="fa fa-user"></i><?php echo get_the_author(); ?></span> 
         <span><i class="fa fa-thumbs-o-up"></i>506</span> 
        </div> 
       </div> 
      </a> 
      <!--end post wrapper--> 
     <?php endwhile; ?> 
    </div> 
    wp_reset_postdata(); 
<?php endif; ?> 

三江源

回答

1

你缺少你查询的关系的一部分,我不知道这是否是唯一的问题,但它应该是这样的:

$args = array(
    'post_type' => 'house', 
    'meta_query' => array(
     'relation' => 'AND', 
     array(
      'key' => 'city', 
      'value' => $_GET["city"], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'part', 
      'value' => $_GET["part"], 
      'compare' => 'LIKE', 
     ), 
     array..... etc, 

希望这会有所帮助

+0

谢谢。但不回答 – Ali

+0

我知道,但还没有能力评论,只是想我应该指出:) –