wordpress-api-client icon indicating copy to clipboard operation
wordpress-api-client copied to clipboard

Typescript Error: Type 'unknown' on fields of Custom Post Types

Open ahamedzoha opened this issue 2 years ago • 1 comments

Describe the bug Extended (Extra) types for Custom Post Types are not working. Getting responses successfully but not the custom fields. Default fields are showing up okay

To Reproduce Steps to reproduce the behavior:

  1. Next 13.2 App
  2. NPM installed npm install wordpress-api-client
  3. Set up custom client
  4. Set up custom types extending WPPost
  5. Created a getter function for Custom type Project
  6. Calling the getter function within a Next Page component
  7. Getting all the data and fields and everything is returned as an array of objects. 8. While mapping over each object, cannot find custom-type fields declared for each project object.

Expected behavior All the default fields for post type AND the custom post type should show up. Added screenshots for better context.

Screenshots types.ts image

client.ts image

index.ts - Here I am creating getter functions image

page.tsx - Here we see the problem image

Here I have marked the ts errors in red You can also see that there is a green checkmark on {project.title.rendered} this is located correctly as this is one of the default fields.

This is making me crazy! Did I goof up somewhere or is this a bug. Please help me out.

Thank you.

ahamedzoha avatar Mar 29 '23 21:03 ahamedzoha

I don't think it's the library's fault.
In my case, WP Custom Fields must be enabled for REST. By default all were false. Check https://learn.wordpress.org/tutorial/wp-rest-api-custom-fields-authentication-and-testing/

That means I had to enable

image

For each damn field 😞

lamuertepeluda avatar Apr 04 '23 16:04 lamuertepeluda