Home Forums Front-end Issues Conditional logic with checkbox


Conditional logic with checkbox

  • 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 ) ) {

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

  • 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.