admin管理员组文章数量:1125559
I'm wondering how to sort a custom post's categories in the selection field which I've circled in the screenshot?
And I have the following code which generates category listing
$args=array(
'class' => 'select-submit2',
'hide_empty' => false,
'selected' => $prop_category_selected,
'name' => 'prop_category',
'id' => 'prop_category_submit',
'orderby' => 'NAME',
'order' => 'ASC',
'show_option_none' => __('None','wpestate'),
'taxonomy' => 'property_category',
'hierarchical'=> true
);
wp_dropdown_categories( $args ); ?>
I'm wondering how to sort a custom post's categories in the selection field which I've circled in the screenshot?
And I have the following code which generates category listing
$args=array(
'class' => 'select-submit2',
'hide_empty' => false,
'selected' => $prop_category_selected,
'name' => 'prop_category',
'id' => 'prop_category_submit',
'orderby' => 'NAME',
'order' => 'ASC',
'show_option_none' => __('None','wpestate'),
'taxonomy' => 'property_category',
'hierarchical'=> true
);
wp_dropdown_categories( $args ); ?>
Share
Improve this question
edited Nov 25, 2020 at 22:50
Tom J Nowell♦
60.7k7 gold badges77 silver badges147 bronze badges
asked Feb 11, 2017 at 20:38
anandmongolanandmongol
1371 gold badge2 silver badges13 bronze badges
6
- Do you have access to the dropdown code? Its a widget? – David Lee Commented Feb 11, 2017 at 21:23
- @DavidLee, I do have access to all the codes, but I don't know specifically which code is the dropdown code. I don't know whether, it's widget or not. But I used the advance search shortcode of theme developer using visual composer. I hope it helps. Thanx – anandmongol Commented Feb 11, 2017 at 21:35
- Need more info to answer – user6686780 Commented Feb 11, 2017 at 22:18
- can you inspect the HTML code, you can see if its a widget of the name there. – David Lee Commented Feb 11, 2017 at 23:14
- Actually you can sort the categories of any post type in the categories screen under the post menu. Just drag and drop the categories in the order you want them to be. Usually all themes reflect this sorting of categories in the front end. – user6552940 Commented Feb 12, 2017 at 9:18
2 Answers
Reset to default 1In your wp_dropdown_categories
function call, you are using 'orderby' => 'NAME'
. This argument is case-sensitive, and it should be 'orderby' => 'name'
(all lowercase).
$args = array(
'class' => 'select-submit2',
'hide_empty' => false,
'selected' => $prop_category_selected,
'name' => 'prop_category',
'id' => 'prop_category_submit',
'orderby' => 'name', // Corrected to lowercase 'name'
'order' => 'ASC',
'show_option_none' => __('None', 'wpestate'),
'taxonomy' => 'property_category',
'hierarchical' => true
);
wp_dropdown_categories($args);
You need to change the orderby
to ID
:
$args=array(
'class' => 'select-submit2',
'hide_empty' => false,
'selected' => $prop_category_selected,
'name' => 'prop_category',
'id' => 'prop_category_submit',
'orderby' => 'ID', //this changed to ID
'order' => 'ASC',
'show_option_none' => __('None','wpestate'),
'taxonomy' => 'property_category',
'hierarchical'=> true
);
wp_dropdown_categories( $args ); ?>
本文标签:
版权声明:本文标题:How to sort custom post's category by id from the theme's function.php? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736663096a1946518.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论