Support

Account

Home Forums ACF PRO JSON (post_name) changes on every save

Solved

JSON (post_name) changes on every save

  • Hi,
    I have noticed a very strange behaviour today. The post_name for an acf-field-group changes on every save and through this a new group_***.json is created on every save as well.

    I first noted this when changes to field groups I made, did not show up in the backend on a custom post type.
    Simultaneously there are several _Notices_ in the _Options_ section of “Edit Field Group”:

    
    Notice: Undefined index: menu_order in advanced-custom-fields-pro/admin/views/field-group-options.php on line 15 
    Notice: Undefined index: position in advanced-custom-fields-pro/admin/views/field-group-options.php on line 26 
    Notice: Undefined index: style in advanced-custom-fields-pro/admin/views/field-group-options.php on line 43 
    Notice: Undefined index: label_placement in advanced-custom-fields-pro/admin/views/field-group-options.php on line 58 
    Notice: Undefined index: instruction_placement in advanced-custom-fields-pro/admin/views/field-group-options.php on line 73 
    Notice: Undefined index: hide_on_screen in advanced-custom-fields-pro/admin/views/field-group-options.php on line 88
    

    I am running WP 4.1 and ACF PRO 5.2.2 (a brief upgrade to ACF PRO 5.2.7 did not resolve the issue).

    Any ideas on what is happening and how to fix it?

  • I haven’t seen anything like this in ACF. My fist guess would be that there is some type of a filter or something that is causing the post to be duplicate rather than updated. The first thing I would do is deactivate other plugins and then if that does not work to try changing to the default WP theme to see if I could narrow down where the incompatibility might be.

  • Thank you for your answer John. I have been going through the default WordPress troubleshooting already, without any luck.

    I narrowed it down to a filter acf/load_field/key= which is used to fill a select dynamically. The obviously problematic part was a WP_Query object:

    
    function allPosts($field)
    {
        $field['choices'] => array();
    
        $query = new WP_Query(array(
            'post_type' => 'any',
            'posts_per_page' => -1,
        ));
    
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
    
                $field['choices'][$query->post->ID] = $query->post->post_title;
            }
        }
    
        return $field;
    }
    

    I substituted this with get_posts() and now it is working again (and yes, there is a reason why I didn’t use a relationship field).

    But there are still some things I’d like to understand:
    a) Why should WP_Query be a problem in this context?
    b) Why didn’t this happen consistently?
    c) Why should a filter be able, to break the post_name of a field group?

    Thank you.

  • That query could most definitely be causing part of you problem. There are 2 things, 1 is that I’m not sure it can work and get what you want, the other is that your not resetting post data.

    
    function allPosts($field)
    {
        global $post; // without this you can't access $post-> below
        $field['choices'] => array();
    
        $query = new WP_Query(array(
            'post_type' => 'any',
            'posts_per_page' => -1,
        ));
    
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post(); // this alters the global $post value
                
                // since your using the_post()
                // may as well use $post here
                $field['choices'][$post->ID] = $post->post_title;
            }
        }
        // reset post data
        wp_reset_postdata();
        return $field;
    }
    
    
  • Thank you for your answer John. I don’t know how I missed that wp_reset_postdata();.

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

The topic ‘JSON (post_name) changes on every save’ is closed to new replies.