WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#30306 closed enhancement (fixed)

wp_dropdown_categories values as slug

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

Description

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 6 years ago.
value_field argument
30306-unit-test.patch (1.7 KB) - added by collinsinternet 6 years ago.
Unit test of added functionality.

Download all attachments as: .zip

Change History (10)

@collinsinternet
6 years ago

value_field argument

#1 @collinsinternet
6 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
6 years ago

  • Component changed from Customize to Taxonomy

@collinsinternet
6 years ago

Unit test of added functionality.

#3 @collinsinternet
6 years ago

  • Keywords has-patch dev-feedback added

#4 @boonebgorges
5 years ago

In 31005:

Use proper hash notation for wp_dropdown_categories() docblock.

See #30306.

#5 @boonebgorges
5 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
5 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
5 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.

Last edited 5 years ago by DrewAPicture (previous) (diff)

#8 @boonebgorges
5 years ago

#13258 was marked as a duplicate.

Note: See TracTickets for help on using tickets.