Support

Account

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');