Support

Account

Home Forums General Issues Dynamically populating a radio in a multisite install

Helping

Dynamically populating a radio in a multisite install

  • Hi Elliot, guys…

    I’m trying to get a radio field populated with another custom field from blog_id=1.

    I actually managed to populate the field correctly (it populates with images) as shown on image backend-1.png

    The code I’m using to populate is something similar to your tutorial:

    function getctas($field) {
        $field['choices'] = array();
        switch_to_blog(1);
    
        $args = array(
            'post_type' => 'location_icons'
         );
    
        $ctas = new WP_Query( $args );
        while ( $ctas->have_posts()) {
            $ctas->the_post();
            $choices = '<img src="'.get_field('icon',false).'"/>';
            $choices = explode("\n", $choices);
            foreach ($choices as $choice){
            	$field['choices'][$choice] = $choice;
            
            }
        }
        restore_current_blog();
        return $field;
    }
    add_filter('acf/load_field/name=call_to_action_icon','getctas');

    The issue I’m getting with this is that when I query the custom post type on front end it looks broken. The images are correctly loading but title field is repeating and description field is not even loading (please refer to broken-fronend image).

    Any clues of what might be happening here?

    Thanks a lot.

  • One more thing, that “Network” title is the title of the first icon CPT. Looks that the part restore_current_blog(); is not making any impact on frontend.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Dynamically populating a radio in a multisite install’ is closed to new replies.