I’m working on a custom WordPress project where I’ve registered a custom post type called parcel. It has several custom meta fields like pickup_pincode, drop_pincode, and delivery_type.
I want to expose these custom fields via the WordPress REST API when fetching the parcel posts (e.g., /wp-json/wp/v2/parcel).
I’ve registered the custom post type using register_post_type, and the meta fields using register_post_meta.
Here’s what I’ve tried in functions.php:
function register_parcel_meta_fields() {
register_post_meta('parcel', 'pickup_pincode', [
'show_in_rest' => true,
'type' => 'string',
'single' => true,
]);
}
add_action('init', 'register_parcel_meta_fields');
I registered the meta fields using register_post_meta() with 'show_in_rest' => true, expecting them to appear automatically in the REST API response for my custom post type parcel. However, when I fetch the data via /wp-json/wp/v2/parcel, the custom fields like pickup_pincode are missing. I expected them to be visible in the JSON response but they’re not showing up. I’m unsure if I need to do more or hook into a different filter.