'键'meta_query无法使用自定义高级搜索(WordPress)

时间:2018-07-09 21:53:19

标签: php wordpress custom-post-type custom-wordpress-pages

现在尝试了几个小时,几乎快要达到临界点了。尝试了很多不同的东西,但似乎无法让我的自定义搜索栏按预定的选择价格范围来查询结果。我正在使用“高级自定义字段”将元标记“ investmentprice”添加到名为“ investments”的自定义帖子类型中。我觉得这与WordPress没有在我的meta_query中选择正确的“键”有关,即使我现在已经做了很多次更改。

以下是配置栏的代码:

vscode.window.createTreeView()

这是我的高级搜索查询功能:

<div class="config_bar cf">
<form method="get" role="search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <input type="hidden" name="s" value="">
    <input type="hidden" name="post_type" value="investments" />

    <div class="col">
        <?php 
            $taxonomy = 'type';
            $args = array( 'orderby' => 'name', 
                'order'             => 'ASC',
                'hide_empty'        => true,
            );      
            $tax_terms = get_terms($taxonomy, $args);
        ?>
        <span class="label_inner">Investment Type</span>
        <select name="type" id="type" class="postform standard">
            <option value="" selected="selected">All Investment Types </option>
            <?php if($tax_terms): ?>
                <?php foreach ($tax_terms as $tax_term): ?>
                    <?php $title = $tax_term->name;
                     ?>
                    <option value="<?php echo $tax_term->slug; ?>"><?php echo $title; ?></option>
                <?php endforeach; ?>
            <?php endif; ?>             
        </select>
    </div><!-- col -->
    <div class="col">
        <span class="label_inner"><?php _e('Select Country','opencloud');?></span>
        <select class="postform standard country " name="country" id="country">
           <option value=""><?php _e('All Countries','opencloud');?></option>
           <?php
           // Display only parents here .
           $terms = get_terms( array(
                // Put your taxonomy name  here.
                'taxonomy' => 'location',
                'parent' => 0, 
                'hide_empty' => false
            ) );

            foreach ($terms as $term){?>
                <!-- We are going to send value for $_POST and data-makeId's TERM_ID for ajax request -->
                <option value="<?php echo $term->slug;?>" data-countryId="<?php echo $term->term_id ?>"><?php echo $term->name;?></option> 
            <?php
            wp_reset_query(); // if you're not in your main loop! otherwise you can skip this
            } ?>
        </select>    
    </div><!-- col -->
    <script type="text/javascript">
        $( document ).ready(function() {
            $('#country').change(function(){
              var $mainCat= $(this).find(':selected').attr('data-countryId');
              if ($mainCat != '0' ){
                // call ajax
                $("#city").empty();
                $.ajax
                (
                  {
                    url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",     
                    type:'POST',
                    data:'action=get_city_lists_ajax&main_catid=' + $mainCat,
                    beforeSend:function()
                    {
                    },
                    success:function(results)
                    {
                      $("#loading_bar").hide();
                      $("#city").removeAttr("disabled").trigger('change.select2');       
                      $("#city").append(results).trigger('change.select2'); 
                    }
                  }
                );   
              }

            });
        });    
    </script>
    <div class="col">
        <span class="label_inner"><?php _e('Select City','opencloud');?></span>
        <select class="postform standard city " name="city" id="city" disabled>
           <option value="<?php echo $term->slug;?>"><?php _e('All Cities','opencloud');?></option>
        </select>    
    </div><!-- col -->
    <div class="col">
        <span class="label_inner">Select Price</span>
        <select class="postform standard price" name="price" id="price">
            <option value="">All Prices</option>
           <option value="500-1000">£500-£1000</option>
           <option value="1000-1500">£1000-£1500</option>
           <option value="1500-2000">£1500-£2000</option>
           <option value="2000-5000">£1500-£2000</option>
           <option value="5000-10000">£5000-£10,000</option>
        </select>    
    </div><!-- col -->
    <div class="col">
        <button class="search_submit" type="submit">Search</button>
    </div><!-- col -->
</form>

}

此外,这是“高级自定义字段”的屏幕截图: Advanced Custom Field (investmentprice)

1 个答案:

答案 0 :(得分:0)

除非有任何其他问题,否则这应该是一个小问题。您在元查询中使用数组键“ terms”而不是“ value”。根据{{​​3}},元查询的嵌套args数组应使用 value ,如下所示:

<?xml version='1.0' encoding='utf-8'?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"><key attr.name="weight" attr.type="string" for="edge" id="d0"/>
<graph edgedefault="undirected"><node id="1"/>
<node id="2"/>
<node id="3"/>
<node id="999"/>
<node id="1029"/>
<node id="1031"/>
<node id="1032"/>
<node id="1197"/>
<node id="1226"/>
<node id="1296"/>
<node id="450"/>
<node id="933"/>
<node id="934"/>
<node id="955"/>
<node id="4"/>
<node id="5"/>
<edge source="1" target="2">
  <data key="d0">1</data>
</edge>
<edge source="1" target="3">
  <data key="d0">1</data>
</edge>
<edge source="2" target="999">
  <data key="d0">1</data>
</edge>
<edge source="2" target="1029">
  <data key="d0">1</data>
</edge>
<edge source="2" target="1031">
  <data key="d0">1</data>
</edge>
<edge source="2" target="1032">
  <data key="d0">1</data>
</edge>
<edge source="2" target="1197">
  <data key="d0">1</data>
</edge>
<edge source="2" target="1226">
  <data key="d0">1</data>
</edge>
<edge source="2" target="1296">
  <data key="d0">1</data>
</edge>
<edge source="3" target="450">
  <data key="d0">1</data>
</edge>
<edge source="3" target="933">
  <data key="d0">1</data>
</edge>
<edge source="3" target="934">
  <data key="d0">1</data>
</edge>
<edge source="3" target="955">
  <data key="d0">1</data>
</edge>
<edge source="3" target="1032">
  <data key="d0">1</data>
</edge>
<edge source="4" target="5">
  <data key="d0">1</data>
</edge>
</graph></graphml>

希望有帮助。