I get the values of the field but now I nothing is showing as selected.
C:\wamp64\www\esmedia\wp-content\themes\ES-Live\templates\template-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)
1461 => string 'Andy McMenemy' (length=13)
1296 => string 'Ann Hiatt' (length=9)
1022 => string 'Anna Read' (length=9)
1745 => string 'April Stallworth' (length=16)
1753 => string 'Arini Vlotman' (length=13)
915 => string 'Atrayah Janhe' (length=13)
2565 => string 'Ayanna Castro' (length=13)
1239 => string 'Bonnie Low-Kramen' (length=17)
1006 => string 'Caitlin Limmer' (length=14)
41952 => string 'Callum Fowler' (length=13)
40313 => string 'Candice Burningham' (length=18)
2571 => string 'Carol Schulte' (length=13)
953 => string 'Carole Spiers' (length=13)
2560 => string 'Cathy Harris' (length=12)
2564 => string 'Chi Chi Okezie' (length=14)
40586 => string 'Christoffer Wahlberg' (length=20)
893 => string 'Christy Crump' (length=13)
40823 => string 'Christy Whyte' (length=13)
40624 => string 'Claire Derrick' (length=14)
40629 => string 'Clodagh Beaty' (length=13)
40461 => string 'Cody Byrns' (length=10)
3654 => string 'Corina Wenzel' (length=13)
1150 => string 'Corinne Hoisington' (length=18)
917 => string 'Cynthia Thomsen' (length=15)
1309 => string 'Cynthia Thomsen and John Shaw' (length=29)
3650 => string 'Danielle De Wulf' (length=16)
895 => string 'Danny McCubbin' (length=14)
2574 => string 'David Holland' (length=13)
983 => string 'David Lovett-Hume' (length=17)
883 => string 'Debbie Gross' (length=12)
3656 => string 'Deborah Marchand' (length=16)
885 => string 'Diana Brandl' (length=12)
911 => string 'Dinah Liversidge' (length=16)
37784 => string 'Don Harms' (length=9)
945 => string 'Donna Gilliland' (length=15)
931 => string 'Dr Veronica Cochran' (length=19)
40541 => string 'Dr. Heather Denniston' (length=21)
42875 => string 'Ed Brenac' (length=9)
40631 => string 'Em Stroud' (length=9)
1153 => string 'Emilie Wain' (length=11)
42392 => string 'Emma Easton' (length=11)
975 => string 'Emma Reynolds' (length=13)
42394 => string 'Emma Ridderstad' (length=15)
957 => string 'Eth Lloyd' (length=9)
41828 => string 'Fiona Walsh' (length=11)
1000 => string 'Hallie Warner' (length=13)
42878 => string 'Hamish Mathers-Jones' (length=20)
40637 => string 'Hana Gray' (length=9)
935 => string 'Heather Baker' (length=13)
1328 => string 'Heather Wright' (length=14)
921 => string 'Helen Monument' (length=14)
1020 => string 'Helen Rees' (length=10)
40718 => string 'Hilary Maxwell' (length=14)
1027 => string 'IMA – International Management Assistants – National Chairmen' (length=73)
1178 => string 'Jack Bradley' (length=12)
1016 => string 'Jackie Ludwig and Sean Magennis' (length=31)
1463 => string 'James Pickles' (length=13)
985 => string 'Jason Allan Scott' (length=17)
998 => string 'Jason Liem' (length=10)
38202 => string 'Jason Whaling' (length=13)
969 => string 'Jeff Lockhart' (length=13)
963 => string 'Jennifer Corcoran' (length=17)
897 => string 'Jeremy Burrows' (length=14)
42396 => string 'Jeremy Dolan' (length=12)
42194 => string 'Jessica McBride' (length=15)
873 => string 'Joan Burge' (length=10)
899 => string 'John Shaw' (length=9)
38234 => string 'Jonathan Bennett' (length=16)
22472 => string 'Julia Leibowitz' (length=15)
901 => string 'Julia Schmidt' (length=13)
42881 => string 'Julie McLellan' (length=14)
933 => string 'Julie Perrine' (length=13)
1008 => string 'Karen Nussbaum' (length=14)
1025 => string 'Kathleen Drum' (length=13)
859 => string 'Kemetia Foley' (length=13)
42037 => string 'Kristie Webber' (length=14)
40588 => string 'Kristine Valenzuela' (length=19)
881 => string 'Laura Belgrado' (length=14)
937 => string 'Laura Schwartz' (length=14)
2567 => string 'Lauren Parsons' (length=14)
42196 => string 'Lea White' (length=9)
879 => string 'Libby Moore' (length=11)
40315 => string 'Lily Shippen' (length=12)
42139 => string 'Lindsay Robinson' (length=16)
42198 => string 'Lisa Gareau' (length=11)
2562 => string 'Lisa Larson' (length=11)
40821 => string 'Lisa Nunn' (length=9)
861 => string 'Lisa Olsen' (length=10)
1302 => string 'Liz Hardwick' (length=12)
996 => string 'Liz Van Vliet' (length=13)
903 => string 'Lizebeth Koloko-Green' (length=21)
2573 => string 'Lucy Bailey' (length=11)
871 => string 'Lucy Brazier OBE' (length=16)
1194 => string 'Lucy Brazier OBE and Melissa Esquibel' (length=37)
949 => string 'Lucy Chamberlain' (length=16)
971 => string 'Maggie Jacobs' (length=13)
1456 => string 'Maria King' (length=10)
40635 => string 'Marianne Whitlock' (length=17)
863 => string 'Marie Herman' (length=12)
967 => string 'Marion Lowrence' (length=15)
919 => string 'Marlize Schneider' (length=17)
965 => string 'Marsha Egan' (length=11)
42044 => string 'Matt Martin' (length=11)
981 => string 'Matthew Want' (length=12)
977 => string 'Melba J Duncan' (length=14)
2563 => string 'Melinda Gates' (length=13)
865 => string 'Melissa Esquibel' (length=16)
41956 => string 'Melissa Peoples' (length=15)
40242 => string 'Michael Levin' (length=13)
990 => string 'Michelle Bowditch' (length=17)
22421 => string 'Mike Thomas' (length=11)
1326 => string 'Naba Ahmed' (length=10)
1186 => string 'Neil Malek' (length=10)
2570 => string 'Nekeisha Nelson' (length=15)
1012 => string 'Nick Ginsburg' (length=13)
2559 => string 'Nicky Christmas' (length=15)
more elements...
'default_value' =>
array (size=0)
empty
'return_format' => string 'array' (length=5)
'multiple' => int 1
'allow_null' => int 0
'ui' => int 0
'ajax' => int 0
'placeholder' => string '' (length=0)
'_name' => string 'scheduled_speakers' (length=18)
'_valid' => int 1
C:\wamp64\www\esmedia\wp-content\themes\ES-Live\templates\template-events.php:332:int 64
How do I get what’s been selected on the front end? In the backend I have Abigail Barnes selected and is showing as selected
Did you ever figure this out? I have a multi select field dynamically filled in the same way too, but on the front end the array for that field is empty
Ok, I’m going crazy now. I am using the select field for multiple choices, the code below works great in the backend – it shows all the speakers cpt’s from site 1, and shows what i’ve selected.
Now just trying to echo out the info on the front end is driving me mad, the array is always empty. I’ve tried get_field and get_field_object, both return with nothing. I even tried putting it in a while loop, but nada
if(have_rows('scheduled_speakers')){
while(have_rows('scheduled_speakers')){
the_row();
echo 'meh';
var_dump(get_field('scheduled_speakers'));
}
}
Not the way I wanted it, but this will do. I would’ve preferred the way the users field shows. I ended up changing it to a multi-option select field
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',
'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/name=speaker_name', 'populate_speakers_field_from_site_1');
IF anyone can figure out how to get the ‘users’ field to work though, that’d be much appreciated! Thanks
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.