0

I'm wondering how to sort a custom post's categories in the selection field which I've circled in the screenshot?

my idea is to sort custom post's categories in the selection field which encircled

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 ); ?>
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 Commented Feb 11, 2017 at 21:35
  • Need more info to answer 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. Commented Feb 12, 2017 at 9:18

2 Answers 2

1

In 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);
0

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 ); ?>
6
  • thanx for the code, but I want to order it by specific order like ID:- 73, 68 , 72 etc etc. Commented Feb 19, 2017 at 15:32
  • wp_dropdown_categories() returns an array? can you add the structure to your question please
    – David Lee
    Commented Feb 19, 2017 at 15:50
  • the above code, seems to sort the category selections in the ascending order. But I want to order the category selection in specific order using the ID. Does it makes sense? plz bear with me. Commented Feb 19, 2017 at 16:07
  • I understand what i want to know is the output of wp_dropdown_categories() to see if we can order with that, if its an array we can iterate to re-order it , or if you have it, the code of the function itself, that will help too.
    – David Lee
    Commented Feb 19, 2017 at 16:13
  • I didn't understand you. Can u plz give me the code? Millions of thanx Commented Feb 19, 2017 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.