Title: using _fields parameter nullify meta keys ?
Last modified: January 6, 2021

---

# using _fields parameter nullify meta keys ?

 *  [kaon68](https://wordpress.org/support/users/kaon68/)
 * (@kaon68)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/using-_fields-parameter-nullify-meta-keys/)
 * Hi there
 * I activated a endpoint for a custom post type, and it returns the fields/meta
   I’ve set in parameters.
 * But when I want to filter the result with the _fields argument, I get only fields
   I want, ok … but the meta doesn’t have value anymore (its null !)
 * I have miss something ?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [jpowersdev](https://wordpress.org/support/users/jpowersdev/)
 * (@jpowersdev)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/using-_fields-parameter-nullify-meta-keys/#post-13882251)
 * Hi [@kaon68](https://wordpress.org/support/users/kaon68/),
 * I am able to filter the API results using the fields parameter on a local test
   install. I also confirmed that querying for a nonexistent field simply omits 
   the field, it isn’t null (so it can’t be that). Do you have any other networking-
   related plugins that may be interfering?
 * Thanks,
    Jon
 *  Thread Starter [kaon68](https://wordpress.org/support/users/kaon68/)
 * (@kaon68)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/using-_fields-parameter-nullify-meta-keys/#post-13891727)
 * Just to complete my problem with an example :
    [https://drive.google.com/file/d/1j4OvqOPruyA9YUWxNHsUdeJmzBj97e-H/view?usp=sharing](https://drive.google.com/file/d/1j4OvqOPruyA9YUWxNHsUdeJmzBj97e-H/view?usp=sharing)
   [https://drive.google.com/file/d/1OGeJD944Vcp2vgazQ6ZeCr2J7rvyQW3f/view?usp=sharing](https://drive.google.com/file/d/1OGeJD944Vcp2vgazQ6ZeCr2J7rvyQW3f/view?usp=sharing)
 * first link is for unfiltered result
    second link I have added “&_fields=id,title.
   rendered,_bbp_forum_id,_bbp_topic_id,_bbp_reply_to,uagb_author_info.display_name”
   on my request
 * For network related extensions, API Bearer Auth to limit to authenticated request.
 *  Plugin Contributor [jpowersdev](https://wordpress.org/support/users/jpowersdev/)
 * (@jpowersdev)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/using-_fields-parameter-nullify-meta-keys/#post-14616882)
 * Hi [@kaon68](https://wordpress.org/support/users/kaon68/),
 * This is a similar problem to [this one here.](https://wordpress.org/support/topic/how-can-i-call-some-parameter/#post-14616864)
   Basically, when you add query parameters to the request, it is no longer handled
   by our plugin’s customization. Since it is then a regular API request, you need
   to register the meta fields with WordPress.
 * Something like this is necessary for each meta field:
 *     ```
       add_action('rest_api_init', function(){
       	register_rest_field('post-type-slug', 'meta_key', array(
       		'get_callback' => function($params){
       			return \get_post_meta($params['id'], 'meta_key', true);		
       		}
       	));
       });
       ```
   
 * This can be done in a loop if you first define an array of necessary meta keys,
   then loop through the keys inside the `rest_api_init` action and register the`
   get_callback` for each one (as seen above).
 * Let me know if that helps,
    Jon

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘using _fields parameter nullify meta keys ?’ is closed to new replies.

 * ![](https://ps.w.org/wp-rest-api-controller/assets/icon-256x256.png?rev=2489942)
 * [WP REST API Controller](https://wordpress.org/plugins/wp-rest-api-controller/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-api-controller/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-api-controller/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-api-controller/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-api-controller/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-api-controller/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [jpowersdev](https://wordpress.org/support/users/jpowersdev/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/using-_fields-parameter-nullify-meta-keys/#post-14616882)
 * Status: not resolved