Support

Account

Forum Replies Created

  • First of all, you can’t use return inside a foreach loop. Second of all, your code is wrong. The function you are using to retrieve images is already echoing on your behalf.

    If you’d like to output the HTML attachment element then you can either get rid of the return keyword or use a different function to first retrieve the url of the image and then echo it yourself as an image.

    See: https://developer.wordpress.org/reference/functions/wp_get_attachment_image/

    Here’s an example for the first method:

    
    $images = get_field('images');
    $size = 'large'; // (thumbnail, medium, large, full or custom size)
    if( $images ){
       foreach( $images as $image_id ){
          wp_get_attachment_image( $image_id, $size );
       }
    }
    

    See: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_url/
    And here’s an example for the second method:

    $images = get_field('images');
    $size = 'large'; // (thumbnail, medium, large, full or custom size)
    if( $images ){
       foreach( $images as $image_id ){
          $image_url = wp_get_attachment_image_url( $image_id, $size );
          echo "<img src='$image_url' "/>;
       }
    }
  • I’m a little bit confused if ACF is capable of something that i’ve been trying to accomplish. What i’d like to have is a seamless syncing of cloned values throughout the site by having all the main components under options page and then cloning them into field groups.

    Right now whenever i use a clone field, the values do not get synced from the options page. So far i’ve accomplished it with this

    add_filter('acf/prepare_field', function($field){
    
        $current_screen = get_current_screen();
        if($current_screen && $current_screen->id == 'toplevel_page_theme-settings') return $field;
    
        $components = get_field('components', 'option');
    
        foreach($components as $component){
    
            if(array_key_exists($field['_name'], $component)){
                
                if(isset($field['sub_fields'])){
                       
                    // foreach($field['sub_fields'] as $field_key => $sub_field){
                    //     foreach($component[$field['_name']] as $sub_component){
                    //         if(array_key_exists($sub_field['_name'], $sub_component)){
                                
                    //             //$field['sub_fields'][$field_key]['value'] = $sub_component[$sub_field['_name']];
                    //             //consoleLog([$field, $sub_field, $sub_component[$sub_field['_name']]]);
    
                    //         }
                    //     }
                    // }
                }else{
                    $field['value'] = $component[$field['_name']];
                }
                
            }
    
        }
    
        return $field;
        
    },10,3)

    But this solution does not work with repeater fields. I am unable to save any repeater fields unless Prefix Field Names is selected but then it is not an exact clone anymore. Also i would like to leave this option untouched so that the user can have a seperate values for specific posts.

    Am i missing something? I’ve been trying to implement this feature for quite some time now but so far i’ve been unuccessful.

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