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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.