Support

Account

Home Forums Bug Reports wp_reset_postdata and acf/load_field issues Reply To: wp_reset_postdata and acf/load_field issues

  • Hi @retribution

    How about manually resetting $post?

    
    add_filter('acf/load_field/name=event_venue_select', array($this->aidee_events_post_management, 'populate_venue_select'));
    
           function populate_venue_select ($field) {
                    
                global $post; 
                $org_post = $post;
                if ($post->post_type=='acf-field-group') return $field; 
                
                // Because ACF custom field management breaks if we return values dynamically. Since we don't need to populate them anyways, we 
                // just return the empty field instead.  
                
                $query_args = array(
                'post_type'  => strtolower($this->cpt_vars['Venue']),
                'paged' => 0,
                'posts_per_page' => -1,
                'post_status' => 'publish',
                
                );
    
                $venues = new WP_Query($query_args);
    
                $field['choices'] = array();
                
                if($venues->have_posts()) : while ($venues->have_posts()) : $venues->the_post();
                    
                    $field['choices'][get_the_id()] = get_the_title(get_the_id());
                
                endwhile;endif;   
                
                $post = $org_post;
                wp_reset_postdata();
                            
                return $field;
                    
            }