logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
Category Drop Down in Plugin Options

I would like to build a category drop down into my plugin options. I can't seem to find the right code to do this. I think I'm almost there, but it not quite.



<select name='radar_options[blog_category]'>
<?php
$categories=get_categories();
foreach($categories as $category) {

$selected = '';
$selected = 'selected="selected"';

echo '<option value="' . $radar_options['blog_category'] . '" ' . $selected . '>' . $category->name . '</option>';


}
?>
</select>




Any help would be appreciated!

Mike

This question has been answered.

Mike McAlister | 06/29/12 at 4:25pm Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    06/29/12
    4:30pm
    Luis Abarca says:


    wp_dropdown_categories


    http://codex.wordpress.org/Function_Reference/wp_dropdown_categories

    Previous versions of this answer: 06/29/12 at 4:30pm

    • 06/29/12 4:31pm

      Mike McAlister says:

      No, not that easy. This is for plugin settings, so you can't just paste wp_dropdown_categories in there.

      Mike

    • 06/29/12 4:35pm

      Luis Abarca says:

      Just get the category from your plugin options



      $radar_options = get_option('radar_options');

      $category_selected = $radar_options['blog_category'];

      wp_dropdown_categories(array('name' => "radar_options[blog_category]", 'selected' => $category_selected) );

    • 06/29/12 4:53pm

      Mike McAlister says:

      This does bring in the categories as it should, but it doesn't seem to be saving. I've tried to echo out the blog_category setting and it returns blank.

    • 06/29/12 4:56pm

      Mike McAlister says:

      Apologies, it DOES work. I had another option resetting it by accident. Good stuff, Luis.

  • avatar
    Last edited:
    06/29/12
    4:53pm
    Kailey Lampert says:

    Luis' answer looks good to me. Where's it falling short for your needs?

    • 06/29/12 4:53pm

      Mike McAlister says:

      This does bring in the categories as it should, but it doesn't seem to be saving. I've tried to echo out the blog_category setting and it returns blank.

    • 06/29/12 4:56pm

      Mike McAlister says:

      He was right, I had a stupid piece of duplicate code screwing things up. D'oh!

This question has expired.



Mike McAlister, Gabriel Reguly, Hai Bui, Arnav Joy voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.