我试图按字母顺序对选项值进行排序,但我不确定最佳方法。目前,代码很好地列出了属性标题,但没有特别的顺序。这是我的代码:
<label><?php _e('Property Name', 'framework'); ?></label>
<select id="pname" style="box-shadow: none;" name="titl" class="form-control input-lg" >
<option value="Any">Any</option>
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=-1&post_type=property');
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<option value="<?php the_permalink(); ?>"><?php the_title(); ?></option>
<?php endwhile; ?>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
wp_reset_query();
?>
</select>
如何按字母顺序对选项值进行排序?
答案 0 :(得分:1)
尝试订购ASC和orderby标题 http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
$wp_query->query('showposts=-1&post_type=property&order=ASC&orderby=title');
那应该有用
答案 1 :(得分:0)
试试这个。
$wp_query = new WP_Query(array(
'showposts' => -1,
'post_type' => 'property',
'order' => 'ASC',
'orderby' => 'title'
));