Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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中对自定义分类父项排序_Wordpress_Sorting_Parent_Taxonomy - Fatal编程技术网

在WordPress中对自定义分类父项排序

在WordPress中对自定义分类父项排序,wordpress,sorting,parent,taxonomy,Wordpress,Sorting,Parent,Taxonomy,我的分类查询中的数组未按父级排序。相反,它是按字母顺序排序的 因此,我有以下自定义列表 名字 电子邮件 国家 陈述 城市 --国家是一种自定义分类法(父分类法) ---国家就是孩子 ----城市将是孩子的孩子 我运行了以下代码查询 $loop = new WP_Query( array( 'post_type' => 'listings', 'taxonomy' =&

我的分类查询中的数组未按父级排序。相反,它是按字母顺序排序的

因此,我有以下自定义列表

  • 名字
  • 电子邮件
    • 国家
      • 陈述
        • 城市
--国家是一种自定义分类法(父分类法)

---国家就是孩子

----城市将是孩子的孩子

我运行了以下代码查询

$loop = new WP_Query( array(
                        'post_type' => 'listings',
                        'taxonomy' => 'listings_region',
                        'parent' => 0,
                        'orderby' => 'parent',
                        'post__in' => $post_ids,
                        'fields' => 'ids',
                    ) );
forloop
中,我将运行一个额外的打印数组以查看区域分类法,它将显示如下:

Array
(
    [0] => WP_Term Object
        (
            [term_id] => 420
            [name] => Connecticut
            [slug] => connecticut
            [term_group] => 0
            [term_taxonomy_id] => 420
            [taxonomy] => listings_region
            [description] => 
            [parent] => 419
            [count] => 1
            [filter] => raw
        )

    [1] => WP_Term Object
        (
            [term_id] => 419
            [name] => USA
            [slug] => usa
            [term_group] => 0
            [term_taxonomy_id] => 419
            [taxonomy] => listings_region
            [description] => 
            [parent] => 0
            [count] => 3
            [filter] => raw
        )

)
我需要找到一种方法把美国放在首位,因为
[parent]=>0

它似乎是按字母顺序排列的

我们将不胜感激

$location = wp_get_post_terms($id, 'listings_region', array('orderby'=> 'parent'));