简体   繁体   中英

ACF: repeater fields returning erratic API data and new fields won't accept new data on save

The site we are working on has broken in the last week and we have no idea what is going on. Here is a list of issues, and the steps we've taken to troubleshoot them:

  • In our API call we are using get_field() and get_fields() to request data from a repeater, but from time to time this returns null, false, or the length of the array. All the content is still in the database.
  • When trying to create new repeater content the child fields of the parent repeater field will not save on first save, but once re-added can be saved afterwards.
  • When creating new fields (any field, not just a repeater) the key will change from the field_xxxxxxxxxxxxxx format to be the same as the name ie short-description.
  • Old repeater fields can be updated or saved to, whereas new ones won't save data.

Troubleshooting Steps

Thanks in advance for any guidance you're able to provide :)

Turns out it was this piece of code in functions.php that we were using to re-write the slugs on save of the posts was the issue:

function myplugin_update_slug( $data, $postarr ) {
    if ( ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
        $data['post_name'] = sanitize_title( $data['post_title'] );
    }
    return $data;
}

The sanitize_title() function was overwriting the key field and causing ACF to lose track of the fields.

We resolved this by activating a clean WP theme, then once we confirmed that it was some code in our child theme we just commented out code in our functions.php file until the offending function was found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM