Support

Account

Home Forums Bug Reports acf/load_field alters $post? Reply To: acf/load_field alters $post?

  • Hello Elliot,

    I changed it to:

    publicic function pre_populate_teams_dropdown( $field ) {
    	global $post;
    	//var_dump( $post );
    	$field['choices'] = array();
    
    	$apollo_home_args = array(
    		'post_type' => 'teams',
    		'nopaging' => true,
    	);
    
    	$apollo_home_teams = get_posts( $apollo_home_args );
    
    	if( count( $apollo_home_teams ) > 0 ) :
    		foreach( $apollo_home_teams as $team ) {
    			$field['choices']['Apollo'][ $team->ID ] = get_the_title( $team->ID );
    		}
    	endif;
    
    	$apollo_away_args = array(
    		'post_type' => 'opponents',
    		'nopaging' => true,
    	);
    
    	$apollo_away_teams = geT_posts( $apollo_away_args );
    
    	if( count( $apollo_away_teams ) > 0 ) :
    		foreach( $apollo_away_teams as $team ) {
    			$field['choices']['Apollo'][ $team->ID ] = get_the_title( $team->ID );
    		}
    	endif;
    
    	return $field;
    }

    This works, however it strikes me as odd. The function get_posts uses WP_Query too and the wp_reset_postdata() filter makes sure the $post variable is restored. So somehow the $post variable isn’t reset the way it should.