我有一些自定义帖子,如果存在元键值,我会尝试获取数据。我有一个Html表单,我正试图在到达和离开时间前取邮件。这是我的表格。
<form action="" method="POST">
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleep">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>
</div>
</div>
这是我的php代码。问题是,我太困惑了,我如何才能通过元键值获取帖子。提交表单时。
<?php
$args = array(
\'post_type\' => \'mad_property\',
\'post_status\' => \'publish\',
\'paged\' => \'-1\',
// \'meta_query\' => $meta_query,
);
$prop_selection = new WP_Query($args);
if( $prop_selection->have_posts() ){
$count=0;
while ($prop_selection->have_posts()): $prop_selection->the_post();
$count++;
if($count > 9){
print \'<div class="property_search_hidden" style="display:none;opacity:0;">\';
}
// if( wpestate_check_booking_valability($book_from,$book_to,$post->ID) ){
get_template_part(\'templates/property_unit\');
if($count > 3){
print \'</div>\';
}
endwhile;
wp_reset_query();
$s=\'\';
if($count > 1){
$s = \'s\';
}
print \'<div class="search_notice"><h3>We found \'.$count.\' item\'.$s.\' for you!</h3></div>\';
if($count > 3){
print \'<div class="col-md-12 show_more_saps"><button onclick="show_hidden_property();" class="btn btn-large btn-saps">Show all \'.$count.\' property were found</button></div>\';
}
}else{
print \'<span class="no_results">\'. esc_html__( "We didn\'t find any results","wpestate").\'</span>\';
}
?>
SO网友:janh
你走对了方向:使用meta_query 在您的查询中。
codex中有很多例子,如何实现它取决于您使用的字段,但这是一条路。查询多个字段的示例:
$args = array(
\'post_type\' => \'product\',
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'color\',
\'value\' => \'blue\',
\'compare\' => \'NOT LIKE\',
),
array(
\'key\' => \'price\',
\'value\' => array( 20, 100 ),
\'type\' => \'numeric\',
\'compare\' => \'BETWEEN\',
),
),
);
$query = new WP_Query( $args );