Support

Account

Home Forums Backend Issues (wp-admin) Fields vanishing in wp-admin

Solving

Fields vanishing in wp-admin

  • Greetings,

    I’ve been battling with this plugin for a few hours, and it’s been extremely frustrating.

    Every time I create fields in a Field Group and click “Update” then exit to export or navigate to the “Custom Fields” root listing and return to my Field Group many of my fields have vanished.

    I had 10 fields, and now only 4 are listed. However the main “Field Groups” listing still shows 10 fields in the Field Group.

    I’d attach a screenshot, but your community does not appear to support that (seriously?)

    So it says I have 10 fields, but if I open the Field Group to edit it, I see 4 fields (2, 5, 7, and 10)

    If I re-order or update, the fields change to (1, 2, 3, and 4)

    And if I update enough, I’m left with a single field.

    I’m using Advanced Custom Fields 4.4.5 and WordPress 4.4.1

    I’m only running 4 plugins: Advanced Custom Fields, Contact Form 7, Landing Pages (by Inbound Now), and Leads (by Inbound Now).

    This issue is made even worse by the fact that you have an export option, but no import option. So I’m left manually recreating all my fields multiple times, only to have them keep randomly vanishing.

    I’ve recreated all my fields about 4 times now, and I’m incredibly sick and tired of setting them up only to see my hard work vanish minutes later.

    Please help!

    Thanks,

    /Chris

  • I’ve just done a test with the plugins you listed installed and active and I’m not seeing the problem that you say your having.

    Try switching to one of the 20XX WP themes. Also try deactivating those other plugins, it could still be something to do with them that I’m not seeing.

    Attaching images to a topic. At the lower left of this window is a paper clip icon. Clicking on this will allow you to attach many types of files, including images.

    Importing. ACF5 Pro includes an import tool. ACF5 Pro is a premium version of the ACF plugin available on the WP repo.

  • I’m using the 2016 theme. The site has no pages, and no posts. Only a single test “landing page” using the Landin Pages plugin.

    I’ve attached 2 screenshots showing the one UI falsely showing 10 fields (which were once there) and the actual fields that remain after 6 were randomly deleted.

    Deactivating the other 3 plugins is not really an option, as those are all needed.

    It’s hard to determine what user-flow is causing the issue so it can be easily replicated.

    I just clicked “update” while viewing my 4 fields and one of them vanished.

    I then hit update a few more times, exited and returned to that section and hit update a few more times but it never removed more.

    I’ve since added another field (bringing me back to 4) and clicking update has not yet removed one of those.

    Not being able to consistently reproduce the bug will make this difficult. It’s entirely possible your test environment has the same bug but has not triggered it yet.

  • There are things that can make fields disappear, but, that usually happens when you have many, many fields and is associated with a PHP setting. From what I can see you don’t have nearly enough fields in the group to cause this.

    What’s really odd is that it appears the fields are all there, because the field order number is not in sequence and it’s like some of the fields are hidden. When you get this happening try inspecting the source of the page and see if you can find a reason that some of the fields may be hidden.

    You could try turning on error reporting and the next time it happens look in your error log to see if any PHP errors occurred. But you’re right, unless you can give me a way to reproduce the error it will be extremely hard to find. https://codex.wordpress.org/Debugging_in_WordPress

  • The fields are not actually there. The stored sort order values for the fields that were not deleted are just never updated. And the count for the total number of fields that shows at the “Field Groups” root level is also not updated.

    I originally did view the source to see if they were just hidden in the UI, but they are gone. And if I touch any of them to change the sort order they update to the proper 1, 2, 3, 4.

    It’s like they are being removed by some process that does not trigger any UI or DB updates for the stored sort and total fields values.

    I currently have a test going with 10 fields. 4 color pickers, 2 text, 2 WYSIWYG, and 2 images. (to see if somehow a specific field type is being removed) or if modifying a specific field type somehow triggers the series of events that ends up with random deletions.

    So far I’ve done everything I can think to do… update values change sort orders, exit the page, export to PHP, click the dreaded update button, and all 10 fields remain.

    That said, I don’t feel even remotely safe as fields have been randomly deleted on no fewer than 6 occasions so far.

    The only difference so far is that this field group has not been exported and used in my template config.php for the Landing Pages plugin. I wonder if somehow the config.php accessing these fields is deleting some of them?

    This is maddening.

  • OK, I just exported the 10 test fields to PHP and copied the ‘fields’ portion of the array (and not the ‘locations’ part) into my theme config.php

    The second I uploaded that PHP file I hit update on the fields group and BOOM, 1 field left.

    So I can create fields, just not use them?

    Here is the code:

    
    if(function_exists("register_field_group")){
        register_field_group(array (
            'id' => 'acf_template-one-a',
            'title' => 'Template One: A',
            'fields' => array (
                array (
                    'key' => 'field_56a2ce14c3f0d',
                    'label' => 'one',
                    'name' => 'main_content_text_color',
                    'type' => 'color_picker',
                    'required' => 1,
                    'default_value' => '#000000',
                ),
                array (
                    'key' => 'field_56a2ce42c3f0e',
                    'label' => 'two',
                    'name' => 'conversion_text_color',
                    'type' => 'color_picker',
                    'required' => 1,
                    'default_value' => '#000000',
                ),
                array (
                    'key' => 'field_56a2f4376cc20',
                    'label' => 'three',
                    'name' => 'another_damn_field',
                    'type' => 'text',
                    'instructions' => 'blah blah blah',
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'formatting' => 'html',
                    'maxlength' => '',
                ),
                array (
                    'key' => 'field_56a2f4d283faa',
                    'label' => 'four',
                    'name' => 'four',
                    'type' => 'text',
                    'instructions' => 'grrrrr',
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'formatting' => 'html',
                    'maxlength' => '',
                ),
                array (
                    'key' => 'field_56a30600484a1',
                    'label' => 'five',
                    'name' => 'five',
                    'type' => 'image',
                    'save_format' => 'object',
                    'preview_size' => 'thumbnail',
                    'library' => 'all',
                ),
                array (
                    'key' => 'field_56a3061ef00f1',
                    'label' => 'six',
                    'name' => 'six',
                    'type' => 'image',
                    'save_format' => 'object',
                    'preview_size' => 'thumbnail',
                    'library' => 'all',
                ),
                array (
                    'key' => 'field_56a30657f81a1',
                    'label' => 'sevin',
                    'name' => 'sevin',
                    'type' => 'wysiwyg',
                    'required' => 1,
                    'default_value' => 'foo',
                    'toolbar' => 'full',
                    'media_upload' => 'yes',
                ),
                array (
                    'key' => 'field_56a3066fdf65c',
                    'label' => 'eight',
                    'name' => 'eight',
                    'type' => 'wysiwyg',
                    'default_value' => '',
                    'toolbar' => 'full',
                    'media_upload' => 'yes',
                ),
                array (
                    'key' => 'field_56a306cdc3924',
                    'label' => 'nine',
                    'name' => 'nine',
                    'type' => 'color_picker',
                    'required' => 1,
                    'default_value' => '#ff0000',
                ),
                array (
                    'key' => 'field_56a306ea011a1',
                    'label' => 'ten',
                    'name' => 'ten',
                    'type' => 'color_picker',
                    'required' => 1,
                    'default_value' => '#00ff00',
                ),
            ),
            'location' => array (
                array (
                    array (
                        'param' => 'post_type',
                        'operator' => '==',
                        'value' => 'landing-page',
                    ),
                    array (
                        'param' => 'template_id',
                        'operator' => '==',
                        'value' => $key,
                    )
                ),
            ),
            'options' => array (
                'position' => 'normal',
                'layout' => 'no_box',
                'hide_on_screen' => array (
                ),
            ),
            'menu_order' => 0,
        ));
    }
    
  • Now I’m really lost about what you’re doing.

    the first thing is that if you export the code and put it into PHP you will completely loose the ability to update the field group through the ACF field group editor. This is going to create duplicate field group IDs and field keys and will likely cause strange things to happen.

    I’ve tried recreating the field group you posted above and updating it, exporting it, returning to the field group, I’m not seeing any problems with it. I’ve even tried disabling the ACF javascrip to see if that could cause a problem.

    The only thing that I can think of here is that some portion of your customization to the theme is causing the issue. You might want to comment it all out and test without it to see if you still have this problem. The only way that anyone is going to be able to help you is if you can figure out what’s causing this to happen and maybe looking at that code will help explain it.

  • I’m confused… what’s the point of exporting the PHP of a field group if using that php on the site causes problems?

    As you mentioned, those steps will not recreate the issue, now that we know the issue is caused by exporting the fields to PHP and then implementing that PHP in a config.php for a template.

    I’m fine with having to re-export the php if I make changes to the field group in ACF. But I don’t understand why the exported PHP running on the site would cause the fields in ACF to vanish.

    In my case I have a template for a landing page that has 2 standard components. a config.php that is used to define the fields for the page, and an index.php that reads those fields.

    All I’m doing is exporting the field group and adding it to the config.php for my template so when I create a page that uses that template the proper fields show up for building the page.

    As far as my customization to the theme, there really isn’t any. The only real PHP contents of the config.php are what I pasted above. (the register_field_group array)

    The only real change to the array is the addition of template_id to the location array:

            'location' => array (
                array (
                    array (
                        'param' => 'post_type',
                        'operator' => '==',
                        'value' => 'landing-page',
                    ),
                    array (
                        'param' => 'template_id',
                        'operator' => '==',
                        'value' => $key,
                    )
                ),
            ),
    

    That is used so the fields are only show up for that specific template.

    I could potentially avoid implementing the exported fields PHP in config.php if there were a way in ACF to add template_id == XXX in locations, but that does not appear to be an option.

    I was able to get things to ALMOST work by removing the register_field_group content form the config.php and then having the ACF field group location target a specific landing page post. The problem there is a single post can implement any number of templates. So I need to target a post that uses a specific template_id, otherwise these fields show up for all landing page posts regardless of template.

    So post_type == landing page is supported, but targeting a specific template is not. (see screenshot)

    So very very close!

  • The point of exporting the field group, in ACF4 is to put it into PHP. At that point you need to delete that field group in the ACF group editor and from that point on you make changes to the field group by editing the PHP, not through the ACF editor. You do this to build an application that does not require the field group recreated, for example if you are creating settings for a theme. When you distribute the theme.

    In ACF5 you can export a field group and then import it into another site, as well as the benefits that I mentioned above.

    If you want to build field groups and have access to editing them AND put them in to a PHP file then you need to have 2 sites. One for building the groups and exporting them and the other where you’re building your theme and loading them with PHP.

    And with the explanation that you’re giving me I think there is a bigger issue.

    If I understand correctly you are attempting to load the field group only when a specific template file is loaded for use in showing a page?

    This will not work. You need to set the location rules to do this and you need to load the fields when WP is being initialized, not when the template is being used, but I could be misunderstanding what your saying. ACF has ways of adding custom location rules if the ones it has are not sufficient. http://www.advancedcustomfields.com/resources/custom-location-rules/ In order to target a specific landing page template for this plugin you’re probably going to need to create a custom location rule.

  • Looks like all I need to do now is add a custom location rule for “template_id” and I’m done. So now I just need to find out how to access that.

    The examples provided at http://www.advancedcustomfields.com/resources/custom-location-rules/ are great. I just need to figure out how to reference “template_id” and load values for existing templates. I’m a bit stumped there for the moment.

    I’m guessing something like this?

    
    add_filter('acf/location/rule_types', 'acf_location_rules_types');
    function acf_location_rules_types( $choices )
    {
        $choices['Basic']['template_id'] = 'Template ID';
    
        return $choices;
    }
    
    add_filter('acf/location/rule_values/template_id', 'acf_location_rules_values_template_id');
    function acf_location_rules_values_template_id( $choices )
    {
        $template_ids = /* somehow get template IDs here */
    
        if( $template_ids )
        {
            foreach( $template_ids as $template_id )
            {
                /* template ID by template name here */
            }
        }
    
        return $choices;
    }
    

    Thanks so much for all the help. It looks like I’m nearly there!

  • Sorry it’s been a while since I got back to you on this.

    landing-pages is a post type and each landing page is a post in the post type. Basically all you need to do is copy the rules used by ACF for either a specific post or a specific page and alter them so that they are looking at the post type used by the other plugin.

    If you look in the ACF4 code in the file /core/location.php you’ll find all of the standard location rules and you can copy the ones you need and make the needed adjustments. Actually, you can use the same rule match function used for matching a post, you just need to add the other filters for adding the choices.

    Hope that helps. Hope this helps.

  • I had some time so I created a generic custom post type filter for matching posts in a custom post type and added it to my filter library here https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-custom-post-type-filters.php

  • Hi John,

    The challenge was that it needed to have a location rule for the post type of landing page (easily done) and a location rule for the template ID used on that post. The developers from Inboundnow were able to make a update to their plugin in their GitHub dev branch that adds the filter for ACF where the template ID is exposed in their code, and we were able to get it working!

    Thanks again for all the help!

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

You must be logged in to reply to this topic.