airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

Custom Field of type true/false gives null instead of false #364

Closed sarahannnicholson closed 3 years ago

sarahannnicholson commented 3 years ago

Making a custom Field of type true/false doesn't end up representing a boolean in the REST API.

Repo steps:

  1. Go to 'Custom Fields' in wordpress's side nav
  2. By 'Field Groups' click 'add new'
  3. Click 'add field'
  4. Fill in the following fields:
    • Field label: my bool
    • Field name: my_bool
    • Field Type: true / false
    • note: notice the default value field is unchecked.
  5. Add a field group name
  6. Click publish (by default the location is on a post)
  7. Go to a post and check your 'my bool' checkbox
  8. Go to the WP rest api /wp-json/wp/v2/posts
  9. Notice your post with the 'my bool' checked is true
  10. Notice your post with not the 'my bool' check is null image

This doesn't follow the rules of a boolean, default / unchecked value should be false. For me this is causing my GraphQL that uses the REST API to not be happy as GraphQL needs a schema, and getting null for a boolean field is causing it to fail.

acf plugin version: 5.9.3 acf pro plugin version: 5.9.3 acf to rest plugin version: 3.3.2 wp version: 5.6

sarahannnicholson commented 3 years ago

This only appears to be an issue when migrating from an older version to this one. Re-creating the custom field causes it to work as intended. Closing as it's super edge case-y. In case someone finds this, just re-make your custom field and add it back to you post types.