我有一些代码可以在Wordpress中按最高价格或最低价格对搜索结果进行排序。
但是我没有相应的表单代码来为代码创建选择器。谢谢
global $query_string;
if($_GET['orderby']=="highestprice") {
$args = array(
'post_type' => 'property',
'posts_per_page' => '-1',
'meta_key' => 'nt_listprice',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'nt_listprice'
)
)
);
} elseif($_GET['orderby']=="lowestprice") {
$args = array(
'post_type' => 'property',
'posts_per_page' => '-1',
'meta_key' => 'nt_listprice',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'nt_listprice'
)
)
);
} else {
$args = array(
'post_type' => 'property',
'posts_per_page' => '-1',
'order'=>'DESC',
'orderby'=> 'post_date'
);
}
这里有一些示例表单代码
<?php if ($nt_option["sp_location"] == "1"): ?>
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
<select class="form-control select" name="locations">
<option value=""><?php if (isset($nt_option["s_location"])) {
echo $nt_option["s_location"];
} ?></option>
<?php $locations = get_terms('location'); ?>
<?php foreach ($locations as $location): ?>
<option value="<?php echo $location->slug; ?>"><?php echo $location->name; ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>