Support

Account

Home Forums General Issues Help with 2 issues

Solved

Help with 2 issues

  • Hi Elliot, sorry about these probably stupid questions, I really tried with the docs and looking for help in the forums but really couldn’t solve this, so getting at you as last remedy since I know you must be very busy.

    Anyway, here are my 2 issues:

    1) Can’t get the size for images in repeater field

    This is the code I’m using:

    <?php 
    $rows = get_field('main_courses');
    
    if($rows)
    {
    foreach($rows as $row)
    {
    echo '<div class="dish">
    <div class="dish-img"><img src="'.$row['main_course_image'].'" alt="" /></div>
    <div class="dish-desc">
    <h4>'.$row['main_course_name'].'</h4>
    <div class="dish-desc-content">'.$row['main_course_description'].'
    </div>
    </div>
    </div>
    ';
    }
    }
    ?>

    The code works fine since it grabs all the info, but I want to get the thumbnail size (or even better, a custom size). I saw there are ways to select the sizes, like this:

    $attachment_id = get_field('field_name');
    $size = "full"; // (thumbnail, medium, large, full or custom size)
     
    wp_get_attachment_image( $attachment_id, $size );

    and others I have found, and I could make it work with no repeater fields, but couldn’t make it work with repeater, probably because I have no idea where to add those lines, or maybe because teh code I’m using for repeater field is no suitable for the images field or whatever. Either way, I hope you can help me with this.

    2) Can’t make it show anything with the following code

    <ul class="colorlist selectable">
    
    <?php if( in_array( 'cblack', get_field('color_choices') ) ): ?>
    <li><a id="black" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/black.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'cred', get_field('color_choices') ) ): ?>
    <li><a id="red" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/red.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'green', get_field('color_choices') ) ): ?>
    <li><a id="green" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/green.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'blue', get_field('color_choices') ) ): ?>
    <li><a id="blue" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/blue.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'pink', get_field('color_choices') ) ): ?>
    <li><a id="pink" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/pink.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'cgray', get_field('color_choices') ) ): ?>
    <li><a id="gray" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/grey.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'corange', get_field('color_choices') ) ): ?>
    <li><a id="orange" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/orange.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'clime', get_field('color_choices') ) ): ?>
    <li><a id="lime" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/lime.jpg" alt="" /></a> </li>
    <?php endif; ?>
    <?php if( in_array( 'csky', get_field('color_choices') ) ): ?>
    <li><a id="sky" class="switcher set1"><img src="<?php bloginfo('template_directory'); ?>/images/sky.jpg" alt="" /></a> </li>
    <?php endif; ?>
    
    </ul>

    I got a similar code from you some time ago and I modified it for another purpose, but this time isn’t showing anything, even though it looks similar (different field names of course). I did check the source just in case the images were missing, but it really didn’t output anything at all, so guess the code has some error, however I tried everything I coudl think of (which as you may imagine is pretty limited) to no avail

    Anyway, thank you in advance and wish you a great and happy new year

  • Hi @cocobongo

    #1
    It looks like you have selected ‘Image URL’ as the return type setting for the image sub field. If you wish to load a custom size via the code posted, you must set the return type to ‘Image ID’. Please read the docs to better understand this.

    #2
    Please debug your variables to visually check if the data is correct and the logic will run. You can debug like so:

    
    <?php 
    
    echo '<pre>';
    	print_r( get_field('color_choices') );
    echo '</pre>';
    die; ?>
    

    Thanks
    E

  • Thank you again Elliot, this solution worked perfectly! 🙂

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

The topic ‘Help with 2 issues’ is closed to new replies.