Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

fetch categories for theme options WordPress

  • SOLVED

Hi,

Based on this: http://themeshaper.com/sample-theme-options/
The dropdown box is populated in a static way. I want to populate the dropdown with categories.
I changed the code to get_categories, but the selected item is not saved.

basically, I need to adapt this code because I want the user of the theme to select a category for the homepage slider.

Answers (2)

2010-06-11

Oleg Butuzov answers:

wp_dropdown_categories()


paul de wouters comments:

I did use that function to populate the dropdown, but $selected is always NULL


Oleg Butuzov comments:

if you are saving somethere data from the update - its should be inside options.

by default you can use get_option('default_category')
after save it depands on your settings that's is saved.


Oleg Butuzov comments:

i think will be better to debug where is select saves. i am not sure you a really saving the values from the dropdown_categories.

2010-06-11

Monster Coder answers:

wp has a function to do that.

$selected = 'xxx'; //it is your current value
wp_dropdown_categories('name=objname&selected='.$selected);



details: http://codex.wordpress.org/Template_Tags/wp_dropdown_categories


paul de wouters comments:

I did use that function to populate the dropdown, but $selected is always NULL


Monster Coder comments:

you have to populate the $selected value from your storage. if it is stored in database, fetch it before calling the function. if it is stored in wordpress option table, use get_option().

otherwise, put your code so experts can help you better.


paul de wouters comments:


$selected = $options['selectinput']; wp_dropdown_categories('name=sample_theme_options[selectinput]&selected='.$selected);


the rest of the code is unchanged. See attached file or http://themeshaper.com/sample-theme-options/

the $options variable gets populated after the submit. the other values are populated correctly.