WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've discovered a workaround to get wp_category_dropdown to display as a multiple select field. My code is as follows:

$sponsors = wp_dropdown_categories( array(
    'child_of' => 0,
    'class' => 'postform',
    'depth' => 0,
    'echo' => 0,
    'exclude' => '',
    'hide_empty' => false,
    'hide_if_empty' => false,
    'hierarchical' => true,
    'order' => 'ASC',
    'orderby' => 'name',
    'selected' => 0,
    'show_count' => 0,
    'show_option_all' => '',
    'show_option_none' => __(''),
    'tab_index' => 0,
    'taxonomy' => 'sponsors', )

$sponsors = str_replace(
    "name='cat' id=",
    "name='cat[]' multiple='multiple' size='19' id=",

So far, so good. Problem is, the above outputs the input name as 'cat' which is fine and dandy unless I need to loop through the above several times and with a more defining name.

As such, I need to have the name of the input be in the following format:

name="scrape[<?php echo $inpCnt; ?>][sponsors]"

However, doing this doesn't work:

$sponsors = str_replace(
    "name='scrape['.$inpCnt.'][sponsors]' id=",
    "name='scrape['.$inpCnt.'][sponsors][]' multiple='multiple' size='19' id=",

So what can I do?

share|improve this question
up vote 2 down vote accepted

The dot . in your code is evaluated as string litral, and not concatenation. Meaning if $inpCnt was equal to 5 for example, php will search for name='scrape['.5.'][sponsors]' id= and will fail to find it. You can either remove the dots while still using the double quotes:

$sponsors = str_replace(
    "name='scrape['$inpCnt'][sponsors]' id=",
    "name='scrape['$inpCnt'][sponsors][]' multiple='multiple' size='19' id=",

.. Or use concatenation:

$sponsors = str_replace(
    'name=\'scrape["'.$inpCnt.'"][sponsors]\' id=',
    'name=\'scrape["'.$inpCnt.'"][sponsors][]\' multiple=\'multiple\' size=\'19\' id=',
share|improve this answer
Duly noted. With that said, it still outputs 'cat' as the input name. – Sweepster Jan 28 '13 at 0:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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