I should have added my current, non-working code. Please be gentle.
$committees = array(
'numberposts' => -1,
'post_type' => 'committee'
);
$query = new WP_Query($committees);
$location_array = array();
if( $query->have_posts() ):
while( $query->have_posts() ): $query->the_post();
$location_array[get_field('committee_name')] = get_field('committee_location');
endwhile;
wp_reset_query();
endif;
That does indeed work beautifully for populating the committee dropdown. Any thoughts on using that selection to set the default values for the meeting fields?
I suppose I could side-step this by coding conditional logic on the template (display meeting_location for this meeting if it exists, else display default_location for this committee), but I think it would be a better user experience for the person creating the meeting to see the default location, and overwrite it if necessary.
Thanks, James. Although this method centers the map, it doesn’t pre-populate the address field or set a marker. And without setting a marker, get_field returns nothing, defeating the purpose of the default value.
And if the default were ever to change, a future person would have to know to edit our functions.php file, including lat and lng values.
The alternative, using the text field, requires first geocoding the text and then integrating those values into Google’s js embed code. I’d hoped to avoid that sort of mucking around.
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.