Support

Account

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

  • 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;
    }