[wp-trac] [WordPress Trac] #33519: Additional choices for 'fields' parameter

WordPress Trac noreply at wordpress.org
Mon Aug 24 09:01:21 UTC 2015


#33519: Additional choices for 'fields' parameter
-------------------------+------------------------
 Reporter:  flixos90     |       Owner:
     Type:  enhancement  |      Status:  closed
 Priority:  normal       |   Milestone:
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:  duplicate
 Keywords:  needs-patch  |     Focuses:
-------------------------+------------------------

Comment (by flixos90):

 @boonebgorges

 it's not that your example doesn't work. My issue is not about performance
 either, it is rather about convenience. The purpose of the `id=>title`
 however would be to receive an array that can immediately be passed to one
 of the many custom-fields/settings-pages frameworks out there (most of
 which accept an array of `'value' => 'label'` for options in dropdowns),
 so we could have a dropdown of posts there. I have been writing foreach
 loops over and over that transform a `WP_Post` array into an array of
 `'ID' => 'post_title'`, so I would say this enhancement is not critical,
 but it would certainly make things quicker for developers.

 Since it is only a convenience enhancement, after hearing your thoughts
 and reading the discussion I see it is probably not worth the effort to
 put it into `WP_Query`.
 My question now is: would it be possible to implement this functionality
 directly into the `get_posts()` function (not the method in `WP_Query`)?
 We could check for the 'fields' argument there, and if it is set to
 something like 'id=>title', we would "memorize" that, overwrite the value
 to an empty string and then execute the usual query. The query result
 would then be transformed to the desired return value directly in the
 `get_posts()` function. This way we would not conflict with any existing
 logic, but still have a way to implement the enhancement.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33519#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list