I have a form that contains a dropdown menu. This form is on a page form.php and is not part of my theme. It exists outside of my site. This dropdown menu contains my list of values for a custom taxonomy called Formats. My Formats are as follows:

Entry Form
  - Entry Form
  - Page

This is my code so far:

<?php include("wp-blog-header.php"); ?>
global $wpdb;
$getFormats = $wpdb->get_results($wpdb->prepare("

        SELECT * FROM wp_terms p 

        LEFT OUTER JOIN wp_term_taxonomy t ON p.term_id = t.term_id

        WHERE t.taxonomy = 'format'

        ")); ?> // This gets all the values for the format taxonomy

<form> //start form
<select name="format"> //start dropdown

foreach ($getFormats as $format) { //spit out the formats
    echo "<option value='".$format->name."'>".$format->name."</option>";
} ?>

</select> //end dropdown
</form> // end form

So far, my dropdown looks like this:

Entry Form
Entry Form

First question: How can I get the hierarchy to stick (i.e. keep the indents)?

My HTML output is as follows:

<option value="Entry Form">Entry Form</option>
<option value="Facebook">Facebook</option>
<option value="Entry Form">Entry Form</option>  // <---- this is gonna be a problem
<option value="Page">Page</option>
<option value="Twitter">Twitter</option>

Second Question: You'll notice the output for the second instance of Entry Form is identical to the first instance. Obviously, this is going to be a problem for submitting the form. How can I make this unique?


You can use the standard WordPress function, get the dropdown already formatted and solve both problems at once.

Like so:

define( 'WP_USE_THEMES', false );
require( './wp-load.php' );

        'child_of' => 0,
        'class' => 'postform', 
        'depth' => 0,
        'echo' => 1,
        'exclude' => '', 
        'hide_empty' => false, 
        'hide_if_empty' => false,
        'hierarchical' => true,
        'id' => '',
        'name' => 'cat-dropdown', 
        'order' => 'ASC',
        'orderby' => 'name', 
        'selected' => 0, 
        'show_count' => 0,
        'show_option_all' => '', 
        'show_option_none' => __('None'),
        'tab_index' => 0, 
        'taxonomy' => 'category',


<select name='cat-dropdown' id='cat-dropdown' class='postform' >
    <option value='-1'>None</option>
    <option class="level-0" value="2">Other</option>
    <option class="level-0" value="1">Uncategorized</option>
    <option class="level-1" value="4">&nbsp;&nbsp;&nbsp;Other</option>
    <option class="level-2" value="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Other</option>

For the default category: categories list

  • I get no output from this, just a white page. – Sweepster Jan 14 '13 at 3:14
  • Figured out the echo option kills the dropdown. Set it to 1 and all's good! – Sweepster Jan 14 '13 at 3:30
  • Oh, that was a left over from testing, answer updated... it's used for $holder = wp_dropdown_categories($args); – brasofilo Jan 14 '13 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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