Drop down not populating categories

I just started wordperss and Im trying to fetch car models from categories into a dropdown list. I tried every possible example I could find but got no output. Im putting this code into my theme's funtions.php.

My category name/slug is Model(model) and id number is 3. It has 4 sub categories under.

$sel = 0;

  $args = array(
                'show_option_all'    => '',
                'show_option_none'   => '',
                'orderby'            => 'ID', 
                'order'              => 'ASC',
                'show_count'         => 0,
                'hide_empty'         => 1, 
                'child_of'           => 3,
                'exclude'            => '',
                'echo'               => 1,
                'selected'           => 0,
                'hierarchical'       => 0, 
                'name'               => 'cat',
                'id'                 => '',
                'class'              => 'postform',
                'depth'              => 0,
                'tab_index'          => 0,
                'taxonomy'           => 'category',

                'hide_if_empty'      => false,
                    'walker'             => ''
  );
   $dropdown = wp_dropdown_categories( $args );

and if I try to print $dropdown it prints blank dropdown.

Answers


If echo is set to 1 it will be displayed directly... If you want to return the dropdown to $dropdown, you have to set echo to 0.


$args = array(
'show_option_all'    => '',
            'show_option_none'   => '',
            'orderby'            => 'ID', 
            'order'              => 'ASC',
            'show_count'         => 0,
            'hide_empty'         => 1, 
            'child_of'           => 3,
            'exclude'            => '',
            'echo'               => 0,
            'selected'           => 0,
            'hierarchical'       => 0, 
            'name'               => 'cat',
            'id'                 => '',
            'class'              => 'postform',
            'depth'              => 0,
            'tab_index'          => 0,
            'taxonomy'           => 'category',

            'hide_if_empty'      => false,
                'walker'             => ''

); $categories = wp_dropdown_categories($args); print_r($categories);

This prints the dropdown list of children of cat 3. Note: It prints only those cats, which are asigned to any posts. ex: Let parent category be 'New'. It has 3 children - 'n1','n2','n3'. If you assign a post with cat 'New', 'n1','n2', then only n1, n2 will be listed in dropdown. Until you assign category to any post, that wont be listed in drop down.


Need Your Help

iPhone SDK: Get GPS coordinates from Google Maps

iphone google-maps gps coordinates

In an iPhone application I'm developing I need to get GPS coordinates to perform some actions based on the values received. Users should have two possibilities of giving the location: