[wp-trac] [WordPress Trac] #28666: Index key support for wp_list_pluck(), à la array_column()

WordPress Trac noreply at wordpress.org
Sat Jun 28 23:07:54 UTC 2014


#28666: Index key support for wp_list_pluck(), à la array_column()
-------------------------+-----------------------------
 Reporter:  trepmal      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 PHP 5.5's [http://us2.php.net/array_column array_column()] has a neat
 third argument for specifying a field to use as the key for the new array.
 Patch adds a third optional argument to wp_list_pluck() that mimics that
 behavior.

 Current functionality is this:

 {{{
 wp_list_pluck( get_posts( ), 'post_title' );
 }}}

 which returns an array like

 {{{
 Array
 (
     [0] => Hello World!
     [1] => Markup: HTML Tags and Formatting
     [2] => Markup: Image Alignment
     [3] => Markup: Text Alignment
     [4] => Markup: Title With Special Characters
 ~`!@#$%^&*()-_=+{}[]/;:'"?,.>
 )
 }}}

 With the patch, you could specify a field to use as the new keys, so
 {{{
 wp_list_pluck( get_posts( ), 'post_title', 'ID' );
 }}}
 would return
 {{{
 Array
 (
     [1699] => Hello World!
     [1178] => Markup: HTML Tags and Formatting
     [1177] => Markup: Image Alignment
     [1176] => Markup: Text Alignment
     [1174] => Markup: Title With Special Characters
 ~`!@#$%^&*()-_=+{}[]/;:'"?,.>
 )
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28666>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list