Home › Forums › ACF PRO › Multisite and changing how the ‘users’ field works › Reply To: Multisite and changing how the ‘users’ field works
Added some error logging, and all the cpt’s are being found
function populate_users_field_with_speakers($field) {
// Switch to Site 1
$site_1_id = 1; // Replace with your Site 1 ID
switch_to_blog($site_1_id);
// Fetch all speakers
$args = array(
'post_type' => 'speakers',
'post_status' => 'publish',
'posts_per_page' => -1
);
$speakers_query = new WP_Query($args);
// Reset choices
$field['choices'] = array();
// Loop through speakers and add to field choices
if ($speakers_query->have_posts()) {
while ($speakers_query->have_posts()) {
error_log('posts found');
$speakers_query->the_post();
$field['choices'][get_the_ID()] = get_the_title();
error_log( $field['choices'][get_the_ID()]);
}
// error_log(var_dump($field['choices']));
wp_reset_postdata();
}else{
error_log('no posts found');
}
// Restore to current blog (Site 2)
restore_current_blog();
return $field;
}
add_filter('acf/load_field/name=speaker_name', 'populate_users_field_with_speakers');
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.