Support

Account

Home Forums Add-ons Repeater Field Img src stays empty

Helping

Img src stays empty

  • Hello,

    I’ve created a repeater field in WordPress containing 3 lines, a title, a link and an image. At the front-end the title and link are working but the img won’t show up.

    My config:`title [text]
    product_image [image] ( ID selected )
    link [link]`

    Front-end:` <?php
    $producten = get_field('products');
    if ( $products)

    print_r( $products);
    {
    foreach ( $products as $product )
    {
    echo '<a href=”'.$product['link'].'” class=”blok”>';
    echo '<h2>';
    echo $product['title'];
    echo '</h2>';
    echo '<img src=”'.$product['sizes']['product_image'].'”>';
    echo '</a>';
    }
    }
    ?> `

    In the functions i’ve specified the image size:`add_image_size( 'product_image', 271, 250, true );
    `

    I’ve also tried to regenerate the thumbnails but this didn’t worked out.

    Hopefully someone has the solution 🙂

    PS: the print_r gives the URL but src stays empty: Array ( [0] => Array ( [titel] => Test [product_image] => 289 [link] => http://****.****.nl/buiten-reclame/ ) )

  • Hi @tanK

    Your code contains a few errors:

    1. You have selected a return type of ID on the image field. This will cause $product[‘product_image’] to contain and ID of the image

    2. Your code references $product[‘sizes’][‘product_image’], but this will never exist. The image ID will sit at $product[‘product_image’]. This is an ID, not a URL

    I think what you want to do is set the image return type to ‘Image Object’, then use this code:

    
    echo '<img src=”'.$product['product_image']['sizes']['product_image'].'”>';
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Img src stays empty’ is closed to new replies.