Viewing 8 replies - 1 through 8 (of 8 total)
  • Your code looks like it should be working properly. Here are 2 recommendations:

    Try using just the following code as a test:

    <?php wp_dropdown_categories(
    $args = array(
    	'exclude' => '0, 9, 12, 43',
    	'show_option_none'   => 'Select Category'
    	)
    ); ?>

    Verify that you are gathering the correct category IDs. In your WordPress admin area go to Posts->Categories and click on one you want to exclude. Verify the ID by looking in the URL for ‘tag_ID’.

    Thread Starter juliedc

    (@juliedc)

    Hi Efuller, Thanks for this. It did add the Select Category but didn’t exclude the categories. Weird.

    Thread Starter juliedc

    (@juliedc)

    I still think this is close to the code I should be using because all of it works except the ‘exclude’ function. I’ve also tried ‘exclude-tree’ but the categories have no hierarchy and that removes all of the categories, not just the ID’s I need to exclude. Still pondering how to accomplish this. Again, any help is appreciated.

    Try using an array instead of a string: array(0, 9, 12, 43)

    Thread Starter juliedc

    (@juliedc)

    or maybe a string instead of a string (didn’t work but i’m not certain of the syntax) because I’ve been using array all along ??

    Thread Starter juliedc

    (@juliedc)

    In the above, I meant try a string because I’ve been using an array which is picking up the “Show Option None” but not the array.

    I’ve also tried using the Simply Exclude which is working when the dropdown is a widget but not when I add this to a template file (single.pho). I’ve also tried adding the entire widget but I get an undefined function error.

    Thread Starter juliedc

    (@juliedc)

    Thank you again, efuller. I was using the count not the ID. The ID no longer shows and I didn’t catch it. I had to use the Reveal ID plugin in order to see the correct id’s. Dang, my vision is not very good.

    This code worked, replacing the numbers with the correct IDs:

    <?php wp_dropdown_categories(
    $args = array(
    	'exclude' => '0, 9, 12, 43',
    	'show_option_none'   => 'Select Category'
    	)
    ); ?>

    Thread Starter juliedc

    (@juliedc)

    Then for the widget, I used Simply Exclude which is not current for WP 4.1 but it worked to exclude category ID’s from the widget.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘wp_dropdown_categories in a template file’ is closed to new replies.