Support

Account

Home Forums Front-end Issues Conditional logic with checkbox

Helping

Conditional logic with checkbox

    • wilfried

    • September 4, 2020 at 11:44 pm

    Hi,

    I’m in a custom-taxonomy template
    I use a loop who works with a get template part.
    I make with ACF a checkBox with the slug bouton_article_format and 4 choice whose patch

    And the idea is if patch is check so put the get template part if not don’t put the get template part.

    My code is this one but is not works …

    $patchButton = get_field('boutton_article_format');
    if ( $patchButton && in_array('patch', $patchButton ) ) {
     get_template_part("template-parts/button-template-loop/button-patch-loop");
    }
    ?>

    I thinks is not works because i use a custom taxonomy template but i’m not sure …

    • xaibi

    • September 8, 2020 at 7:20 pm

    I am still not sure, may be this will work for you. You have to add your fields in first line and you have to multiple times for multiple checkboxes.

    <?php $values = get_field('MYFIELD', $post->post_parent); if(in_array("CHECKBOX_NAME", $values )){ ?>
    
    <?php get_template_part("template-parts/button-template-loop/button-patch-loop"); ?>
    
    <? } ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.