Support

Account

Home Forums General Issues How to add ACF checkbox field to JS script?

Helping

How to add ACF checkbox field to JS script?

  • Hi

    I have this part of code:

    $(document).ready(function () {
        $('.c-slider__item').owlCarousel({
            animateOut: 'fadeOut',
            animateIn: 'faceIn',
            items: 1,
            loop: true,
            autoplay: true,
            autoplayTimeout: 5000,
            autoplayHoverPause: true,
            mouseDrag: true,
            nav: true,
            dots: false,
            lazyLoad: true,
            navText: [
                '<span aria-label="' + 'Previous' + '"><i class="fas fa-caret-left"></i></span>',
                '<span aria-label="' + 'Next' + '"><i class="fas fa-caret-right"></i></span>'
            ],
    });

    and now I need add checkbox conditional, so I create:

    (...)
    nav: '<?php
            // vars	
            $slider_options = get_field('slider_options');
            // check
            if( $slider_options && in_array('nav', $slider_options) ): ?>
            true
            <?php endif; ?>',
    (...)

    but I can’t get the “true” value on frontend. I was trying with “value”, “label” and “both (array)” options in Checkbox field settings, but without results. How should I do it right?

  • Hello Damian,

    I think you forgot some quotes
    maybe like this

    $slider_options = get_field('slider_options');
            // check
            if( $slider_options && in_array('nav', $slider_options) ): ?>'
            true;
            '<?php endif; ?>'
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.