Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#30306 closed enhancement (fixed)

wp_dropdown_categories values as slug

Reported by: gputignano's profile gputignano Owned by: boonebgorges's profile boonebgorges
Milestone: 4.2 Priority: normal
Severity: normal Version: 4.0
Component: Taxonomy Keywords: has-patch dev-feedback
Focuses: Cc:


wp_dropdown_categories returns value attribute in option tag as a numeric value. It could be better to choose it between an id or slug. For example if I want to filter a post list by a taxonomy I have to set taxonomy value to slug in global $query var.

Attachments (2)

30306.patch (948 bytes) - added by collinsinternet 10 years ago.
value_field argument
30306-unit-test.patch (1.7 KB) - added by collinsinternet 10 years ago.
Unit test of added functionality.

Download all attachments as: .zip

Change History (10)

10 years ago

value_field argument

#1 @collinsinternet
10 years ago

This isn't a bad idea. You could add an argument to the wp_dropdown_categories() called 'value_field' and set the value as 'slug' or any other part of the $category object (e.g. 'name').

#2 @ocean90
10 years ago

  • Component changed from Customize to Taxonomy

10 years ago

Unit test of added functionality.

#3 @collinsinternet
10 years ago

  • Keywords has-patch dev-feedback added

#4 @boonebgorges
9 years ago

In 31005:

Use proper hash notation for wp_dropdown_categories() docblock.

See #30306.

#5 @boonebgorges
9 years ago

  • Milestone changed from Awaiting Review to 4.2

This seems like a good idea, and will mitigate the issue described in #30865. Let's do it.

#6 @boonebgorges
9 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 31006:

In wp_dropdown_categories(), allow the term field used to populate option valuesto be specified.

The new 'value_field' parameter makes it possible to set term slugs (or some
other term property) as the 'value' attribute of the option elements generated
by wp_dropdown_categories(). This additional flexibility reduces the effort
required to translate term_id to other term fields when processing form
submissions that include values from taxonomy dropdowns. See #30865 for a
use case.

Props collinsinternet.
Fixes #30306.

#7 @DrewAPicture
9 years ago

In 31357:

Update the DocBlock for wp_dropdown_categories() to reflect that the entire $args parameter array is optional instead of individual arugments.

See #30306.

Version 0, edited 9 years ago by DrewAPicture (next)

#8 @boonebgorges
9 years ago

#13258 was marked as a duplicate.

Note: See TracTickets for help on using tickets.