我想通过ID和ID顺序获取术语。但这不起作用,WP会自动更改顺序。
我的代码-
$catsArray = array(159, 155, 143, 153, ......);
$series = get_terms( array(
\'taxonomy\' => \'ctc_sermon_series\',
\'number\' => 9,
\'offset\' => $offset,
\'include\' => $catsArray,
\'hide_empty\' => false,
) );
结果呢-
(
[0] => WP_Term Object
(
[term_id] => 155
[name] => 10
[slug] => 10
[term_group] => 0
[term_taxonomy_id] => 155
[taxonomy] => ctc_sermon_series
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
)
[1] => WP_Term Object
(
[term_id] => 159
[name] => 14
[slug] => 14
[term_group] => 0
[term_taxonomy_id] => 159
[taxonomy] => ctc_sermon_series
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
)
[2] => WP_Term Object
(
[term_id] => 153
[name] => Name 8
[slug] => name-8
[term_group] => 0
[term_taxonomy_id] => 153
[taxonomy] => ctc_sermon_series
[description] => Name 8 Des
[parent] => 0
[count] => 1
[filter] => raw
)
[3] => WP_Term Object
(
[term_id] => 143
[name] => Series 1
[slug] => series-1
[term_group] => 0
[term_taxonomy_id] => 143
[taxonomy] => ctc_sermon_series
[description] => Series 1 Description
[parent] => 0
[count] => 3
[filter] => raw
)
)
我希望首先得到ID-159的term结果,但每次我都首先得到ID-155的结果。我需要通过ID的数组序列获得结果。
提前感谢:)
最合适的回答,由SO网友:nibnut 整理而成
因此,我认为问题是如何按照您提供的ID的顺序获取术语-可能不是升序或降序,而是随机顺序。
令人惊讶的是,我认为WP中有一条捷径——谁知道呢?我相信这就是你想要使用的:
$catsArray = array(159, 155, 143, 153, ......);
$series = get_terms( array(
\'taxonomy\' => \'ctc_sermon_series\',
\'number\' => 9,
\'offset\' => $offset,
\'include\' => $catsArray,
\'hide_empty\' => false,
\'orderby\' => \'include\', // <---
) );
希望这有帮助!
SO网友:Anwer AR
这可能对你有用,虽然我没有测试过。
$catsArray = array(159, 155, 143, 153, ......);
$series = get_terms( array(
\'taxonomy\' => \'ctc_sermon_series\',
\'number\' => 9,
\'offset\' => $offset,
\'include\' => $catsArray,
\'hide_empty\' => false,
\'orderby\' => \'term_id\',
\'order\' => \'DESC\', // or ASC
) );