Home › Forums › Bug Reports › acf/load_field alters $post? › Reply To: acf/load_field alters $post?
public function pre_populate_teams_dropdown( $field ) {
$field['choices'] = array();
$apollo_home_args = array(
'post_type' => 'teams',
'nopaging' => true,
'fields' => 'ids',
);
$apollo_home_teams = new WP_Query( $apollo_home_args );
if( $apollo_home_teams->have_posts() ) :
while( $apollo_home_teams->have_posts() ) : $apollo_home_teams->the_post();
$field['choices']['Apollo'][$post] = get_the_title( $post );
endwhile;
wp_reset_postdata();
endif;
$apollo_away_args = array(
'post_type' => 'opponents',
'nopaging' => true,
'fields' => 'ids',
);
$apollo_away_teams = new WP_Query( $apollo_away_args );
if( $apollo_away_teams->have_posts() ) :
while( $apollo_away_teams->have_posts() ) : $apollo_away_teams->the_post();
$field['choices'][__( 'Opponents', 'apollo' )][$post] = get_the_title( $post );
endwhile;
wp_reset_postdata();
endif;
return $field;
}
Appears to work as well.
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.