Support

Account

Home Forums Add-ons Repeater Field Conditional Checkbox Statement in Repeater

Solved

Conditional Checkbox Statement in Repeater

  • I have a repeater field that creates a “scrolling” gallery. I want to be able to allow each repeater item to have different options, so I added a checkbox to each repeater. One of the values is to add a an image border.

    Here is what I’ve been using:


    <?php if( in_array( 'border', get_field('blog_style_gallery_options') ) )
    {
    echo "border";
    }
    ?>

    The word “border” calls the image class which styles the image with the border.

    This entire code works fine if the options are not in the repeater, but AFTER the repeater as a global option… however I want to be able to add image borders to selected images, not all of them at once.

    When I use the code in a repeater, I get the following error:

    Warning: in_array() [function.in-array]: Wrong datatype for second argument

    Help!

  • Is the checkbox just a true/false field? If so it would be:

    
    <?php 
    if ( get_sub_field('blog_style_gallery_options') ) {
      echo "border";
    }
    ?>
    
  • It’s not a true/false field, it’s a checkbox field… because I want to have several options to modify my images (like border, remove link, remove hover effect, etc).

  • This was solved by ACF Support.

    Here is the code if anyone is interested:

    <?php 
    $chckbox_value = get_sub_field('blog_style_gallery_options');
    if( $chckbox_value && in_array( 'border', get_sub_field('blog_style_gallery_options') ) )
    {
        echo "border test";
    }
    ?>
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Conditional Checkbox Statement in Repeater’ is closed to new replies.