I am using this which lists all posts from a CPT on site 1, from site 2 (multisite wordpress site).
On site 2, I select the name in the select field and shows as selected after the page has updated, but on the front-end of the site there are no values selected. CAn anyone help me figure this out please?
function populate_speakers_field_from_site_1($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',
'orderby' => 'title',
'order' => 'asc',
'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()) {
$speakers_query->the_post();
$field['choices'][get_the_ID()] = get_the_title();
}
wp_reset_postdata();
}
// Restore to current blog (Site 2)
restore_current_blog();
return $field;
}
add_filter('acf/load_field/key=field_6699142ff52aa', 'populate_speakers_field_from_site_1');
and to retrieve the data I’m just doing a simple var_dump(get_field_object('field_6699142ff52aa'));
C:wamp64wwwesmediawp-contentthemesES-Livetemplatestemplate-events.php:241:
array (size=26)
'ID' => int 244
'key' => string 'field_6699142ff52aa' (length=19)
'label' => string 'Speakers Names' (length=14)
'name' => string 'scheduled_speakers' (length=18)
'aria-label' => string '' (length=0)
'prefix' => string 'acf' (length=3)
'type' => string 'select' (length=6)
'value' =>
array (size=0)
empty
'menu_order' => int 9
'instructions' => string '' (length=0)
'required' => int 0
'id' => string '' (length=0)
'class' => string '' (length=0)
'conditional_logic' =>
array (size=1)
0 =>
array (size=1)
0 =>
array (size=3)
...
'parent' => int 150
'wrapper' =>
array (size=3)
'width' => string '' (length=0)
'class' => string '' (length=0)
'id' => string '' (length=0)
'choices' =>
array (size=179)
947 => string 'Abigail Barnes' (length=14)
1163 => string 'Abigail Barnes and Helen Rees' (length=29)
42137 => string 'Abigail Rudner' (length=14)
1002 => string 'Adam Hergenrother' (length=17)
1004 => string 'Adam Hergenrother and Hallie Warner' (length=35)
41950 => string 'Ali Pasha' (length=9)
959 => string 'Alice Scutchey' (length=14)
38242 => string 'Alicia Fairclough' (length=17)
40584 => string 'Aliina Rowe' (length=11)
2566 => string 'Amanda Johnson' (length=14)
1458 => string 'Amy McKeown' (length=11)
907 => string 'Andrea Macarie' (length=14)
etc etc
947 => string ‘Abigail Barnes’ is the selected person in the select, but as you can see, the values are empty.
I am wanting the selected people (in this case Abigail Barnes) to be displayed only so I can do a database search with their ID’s