Support

Account

Home Forums ACF PRO API returning erratic data from repeater fields, data not saving

Solved

API returning erratic data from repeater fields, data not saving

  • Hello all!

    A site I’ve been working on has began to erratically return different data from the API call that I created. It has also become difficult to save data to new fields, or to create new field groups. Here is a list of issues, and the steps we’ve taken to troubleshoot them (I’ve also attached a copy of our functions file. We are using the latest version of ACF PRO 5):

    – the 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 i.e short-description.
    – Old repeater fields can be updated or saved to, whereas new ones won’t save data.

    Troubleshooting Steps

    – Deactivated all plugins
    – Clean install of ACF PRO 5
    – Changed WordPress user permissions to default settings: https://www.stevejenkins.com/blog/2015/09/correct-permissions-for-wordpress/
    – Used WP Optimize and Sweep plugins to clean DB
    – Increase our max_vars settings: https://www.advancedcustomfields.com/resources/limit-number-fields/
    – Tried this way to register post types: https://www.freshconsulting.com/wordpress-custom-post-types-advanced-custom-fields/
    – Attempted to build field groups with PHP in functions file (nothing happened): https://www.advancedcustomfields.com/resources/register-fields-via-php/
    – Attempted to build fields from exported JSON files, changing the keys to be unique (field group was visible through the dashboard, but some fields wouldn’t import, not saving error still persists, and adding the field group to a post type is buggy)

    Thanks in advance for any guidance you’re able to provide 🙂

    Lucas

  • 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.

  • Glad you got this worked out, I was about to tell you to look for a filter that was altering the post slug as soon as I read this.

    – 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 i.e short-description.

    and then I scrolled down to see that you’d solved it.

    My main reason for posting is to say thank you for the way you posted your problem. If you hadn’t solved this problem yourself the amount of detail you gave made it extremely easy to narrow down what the underlying issue was.

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

The topic ‘API returning erratic data from repeater fields, data not saving’ is closed to new replies.