get_posts
passes the heavy lifting off to WP_Query
and if you look at the source of that class you can see that there are only a limited number of options with that fields
argument. There are only three options in that switch
— ids
, id=>parent
, and the default case, everything.
You can use the posts_fields
filter to alter what fields get returned, though it looks like you need to pass 'suppress_filters => false
in the arguments in order to get that filter to run. It should look something like this:
function alter_fields_wpse_108288($fields) {
return 'ID,post_title'; // etc
}
add_filter('posts_fields','alter_fields_wpse_10888');
However, there is a larger problem. The post objects that get returned are created by a call to get_post
and it doesn’t honor the values passed into the original query and I don’t see a way to change what gets returned either in get_posts
or in the WP_Post
class itself.
Related Posts:
- Why Does get_posts() Return an Empty Set?
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- Ordering posts by metadata
- get_posts() not working when accessing with a custom user role
- get post attachment using ajax
- How to get post content by get_posts function?
- Why does my widget break other widgets?
- What’s wrong with this post__not_in argument?
- Delist entries in the_loop
- Custom query not working in plugin admin page
- How do I query posts and have their related taxonomies returned in the results?
- filter on get_posts efficiently
- A better way of getting draft posts that has a particular post meta using get_posts function
- How to debug a plugin with Xdebug?
- Change default admin page for specific role(s)
- Check for dependent plugin and if false dont activate plugin
- How to check username/password without signing in the user
- Show message on wordpress admin dashboard
- Log in from one wordpress website to another wordpress website
- What’s the earliest point I can get the queried object ID?
- Custom admin_notices Messages Ignored During Redirects
- Show a user their recently viewed posts
- How is the data stored in the database?
- Is it save to require plugin.php early to be able to use get_plugin_data() earlier?
- When is it appropriate to put functions on page template vs. functions.php?
- How to prevent loading of all plugin’s resources?
- Unit Testing a Plugin functionality with cron
- How to enable users to down-vote in this simple voting counter (that uses the post meta)?
- Is it possible for a plugin to register a page template file?
- Best way for plugin to accept POSTs?
- What are the really difference writing WordPress 3.x widget plugins?
- Error “Call to a member function switch_to_locale() on null” during insert_with_markers
- multiple functions with same filter
- Calling plugins API within a theme
- How do you output enqueued scripts to an admin page?
- Woocommerce – Hide a Column in Cart Table
- Generate dynamic page through data from another page
- Does WordPress’s HTTP API use any caching?
- query users by role
- call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members
- How to Create Custom HTML Tag on Editor in `Text(HTML)` mode
- null callback in add_settings_section
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- How long should it take for a plugin to fully load into the WordPress.org plugin repository?
- Which directory in my plugin repo does WordPress Plugin Directory package?
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- Replace default Blogroll Links with Social Media Links
- How to enqueue or include json file to a plugin
- Search and Filter
- Show error, when selecting image in WordPress media uploader if params mismatch
- Trying to code a simple plugin, infinite loop?
- Update own Plugin Repository on Multisite
- How to exit a plugin’s execution mid-stream?
- Issue with contextual help overwriting existing content
- Inserting code to HTML view from a pop up initiated from visual view
- CSS not affecting widget output
- Redeclaring a plugin function within a class
- Using a custom shortcode from within the template of a shortcode plugin
- enqueue script/style plungin development
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- How to create a WordPress Plugin that has it’s own “page”?
- How to Add a Custom Size for Thumbnails for WP – Gallery
- Create Widget or Enable Shortcodes in Sidebar
- Will I get an error if I try unscheduling a WP Cron scheduled task that wasn’t scheduled?
- Conditional Generation of Image Sizes using add_image_size
- Plugins and caching
- Display time difference (6 hours ago) in a Soliloquy caption
- Empty Array is Giving Warning for array_merge()
- how to create category with code in wordpress using form
- Is it possible to have instead mypage.com/?page_id=81 to have mypage.com/cool/?
- User Data Handling between two plugins
- Pass custom props to
- Translations only load from `wp-content/languages/plugins` but not from the plugin’s languages folder
- Woocommerce place order update shipping price
- GET request return value as error instead of success
- How to update global variables in plugin activation callback?
- How to include a page template and template part into my plugin
- WP_Fatal_Error_Handler OR WP_Error OR try/catch
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- ajax response strips multidimensional array and unable to decode
- Multiple instances of $opt_name in redux framework
- Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework
- The Events Calendar featured image as body background?
- Pass javascript result to shortcode executer function
- Not able to Update database while creating a custom module
- Plugins and how to assign urls to content
- How to make auto installer Plugin?
- problem with blank page
- Use custom clean URLs for a plug in
- Cannot echo a JS variable to a jQuery plugin coming from wp_localize_script
- first_name property missing inside register_user action hook
- Pass results of custom query to loop – when writing a plugin
- Plugin SVN folder structure
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- user can login from single account detail from multiple locations(computer) at the same time [closed]
- Need someone to help you want to manage points for members to code interface functions? thank you
- Call API on post save/update and show the result in admin area
- Is there any other ways to replicating changes on live from staging without pushing from git
- Run different permission_callback depending on HTTP method of custom REST API endpoint
- upload image to wordpress media library failed for custom post type