Support

Account

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

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