From c9c9af5df891e3face6176e41fd1a241fb2aecdc Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 5 Feb 2015 19:03:52 +0000 Subject: [PATCH] Introduce `'value_field'` parameter to `wp_dropdown_pages()`. This parameter allows developers to choose the post field that will be used to fill in the 'option' attribute of the generated dropdown markup. See [31006] #30306 for a parallel enhancement in `wp_dropdown_categories()`. Props jfarthing84. Fixes #12494. git-svn-id: https://develop.svn.wordpress.org/trunk@31338 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-template.php | 16 +++++-- tests/phpunit/tests/post/template.php | 68 ++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 927c6592cd..e91358ec6a 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -971,7 +971,8 @@ function wp_dropdown_pages( $args = '' ) { 'selected' => 0, 'echo' => 1, 'name' => 'page_id', 'id' => '', 'show_option_none' => '', 'show_option_no_change' => '', - 'option_none_value' => '' + 'option_none_value' => '', + 'value_field' => 'ID', ); $r = wp_parse_args( $args, $defaults ); @@ -1425,15 +1426,20 @@ class Walker_PageDropdown extends Walker { * @since 2.1.0 * * @param string $output Passed by reference. Used to append additional content. - * @param object $page Page data object. - * @param int $depth Depth of page in reference to parent pages. Used for padding. - * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element. + * @param object $page Page data object. + * @param int $depth Depth of page in reference to parent pages. Used for padding. + * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option + * element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}. * @param int $id */ public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { $pad = str_repeat(' ', $depth * 3); - $output .= "\t