Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress中的PHP排序_Php_Wordpress - Fatal编程技术网

Wordpress中的PHP排序

Wordpress中的PHP排序,php,wordpress,Php,Wordpress,这是一个非常新的问题。但是我该如何按字母顺序对结果进行排序,以使li列表中的名称有序 <?php // FOR THE CATEGORIES (PRODUCT TYPE) $terms_one = get_terms('product_cat'); $count_one = count($terms_one); $i_one = 0; echo '<ul class="submenu one filter option-set" data-filter-group="gem

这是一个非常新的问题。但是我该如何按字母顺序对结果进行排序,以使li列表中的名称有序

<?php 
// FOR THE CATEGORIES (PRODUCT TYPE)
$terms_one = get_terms('product_cat');
$count_one = count($terms_one);  
$i_one = 0; 

echo '<ul class="submenu one filter option-set" data-filter-group="gem-type">';
echo '<li><a href="javascript:void(0)" data-filter-value="" class="selected">ALL</a>';

if ($count_one > 0) {        
foreach ($terms_one as $term_one) 
{
    $i_one++;      
    $term_list_one .= '<li><a href="javascript:void(0)" data-filter-value=".'. $term_one->slug .'"> <span>'. $term_one->count .'</span>'. $term_one->name .'</a></li>';

    if ($count_one != $i_one) 
    {
        $term_list_one .= '';
        } else {
        $term_list_one .= '';
    }
} 
  echo $term_list_one;
}
echo '</ul>';
?> 

试试看

在执行
foreach
循环之前


如果要按数组键进行排序,可以使用
ksort()
..

get\u terms()
函数中放入带有参数的数组,
orderby
order
可能就是您想要的

以下是文档:


更多信息,请参阅此处的文档:

谢谢Jamie。这就是我用的。当它不起作用时,我想我一定是做错了。我正在尝试分类。也许他们做了一些不允许排序的棘手事情?
asort($terms_one);
$terms_one = get_terms('product_cat','orderby=FIELD&order=ASC');