Support

Account

Home Forums Backend Issues (wp-admin) Unable to add fields/existing fields disappeared

Solving

Unable to add fields/existing fields disappeared

  • Hello,

    I’ve been using ACF successfully until something very odd happened today. I went in to edit a Custom Field Group, and after adding a field and clicking ‘Update’, all the existing fields disappeared (including the one I tried adding). I quickly went to check the WordPress page on the backend they were meant to appear on, and it was empty. I then came back to the ACF dashboard and it listed the group as having “0” fields, they were all gone. From this point on if I try and create a field in any Field Group it disappears as soon as I click ‘Update’ (and I assume the rest will disappear as well, but I’ve only tested via making new Field Groups as to not risk deleting everything).

    Any idea why this would have happened? I have one other Field Group on the website that contains nearly all the content for the website, and I’m worried to touch it as if it disappeared everything would be gone. I’ve activated and deactivated the plugin and the issue persists. I’ve considered deleting and re-installing the plugin but imagine that would result in all the text input into the custom fields to be lost.

    My questions are:
    1. Has anyone else experienced this or know why this would have happened?
    2. Is the text which was input into these fields, which are now gone, saved anywhere? I ask this especially in case the same thing happens to my other Field Group, which has hundreds of entries in the various ACF text fields on each post.

    Thanks very much for your time, any help is greatly appreciated.

  • I had the below code in my functions.php file and after removing it the problem seems to have gone away (as in I can now create fields without them disappearing, the Field Group that had the fields who disappeared in it is still empty, but I will rebuild and now see that the content still lives in the database). The below code was to take some text from an ACF and change the slug of the post to that text.

    add_action('save_post', 'change_default_slug');
    
    function change_default_slug($post_id) {
    
    //Check it's not an auto save routine
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
    return;
    
    //Perform permission checks! For example:
    if ( !current_user_can('edit_post', $post_id) ) 
    return;
    
     //Check your nonce!
    
    //If calling wp_update_post, unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'change_default_slug');
    
    // call wp_update_post update, which calls save_post again. E.g:
    wp_update_post(array('ID' => $post_id, 'post_name' =>get_post_meta($post_id,'request_number',true)));;
    
    // re-hook this function
    add_action('save_post', 'change_default_slug');
    }

    Interested to hear why this might have caused a conflict, but grateful that the problem is gone!

  • The problem is that your filter runs on all post types. ACF field groups work just like any other post type and ACF uses itself to save the fields the same way that it saves values for our custom fields.

    At any rate, what you need to do is make sure you’re only doing this on the post types you need it to happen on.

    
    add_action('save_post', 'change_default_slug');
    
    function change_default_slug($post_id) {
    
    if (get_post_type($post_id) != 'your-post-type') {
      return;
    }
    
    //Check it's not an auto save routine
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
    return;
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.