Support

Account

Home Forums ACF PRO Multisite and changing how the ‘users’ field works Reply To: Multisite and changing how the ‘users’ field works

  • 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