Support

Account

Home Forums Front-end Issues the_field() with checkbox as class for html

Unread

the_field() with checkbox as class for html

  • Hi,

    So I’m kind of new to php, not a huge user but it’s the first time I encounter this situation.

    I’m using a checkbox (with multiple choices) and I’d like to use it in a html tag.

    To put it simply, my checkbox goes from 1 to 5 choices and each choice is a class in my css and I’d like to put all the choice in a html tag like that (if all of them are check, they all show, if 4 are checked those 4 show, etc.) :

    <article class="choice1 choice2 choice3 choice4 choice5">blabla</article>

    What I’m doing is:

    <article class="<?php the_field('checkbox'); ?>">blabla</article>

    but it display as:

    <article class="choice1, choice2, choice3, choice4, choice5">blabla</article>

    I tried to use do this:

    $a = the_field('checkbox');
    $a = str_replace(",", " ", $a);

    but when I do

    echo $a

    I still get choice1, choice2, choice3, choice4, choice5 instead of choice1 choice2 choice3 choice4 choice5

    I saw somewhere that I have to use get_field instead of the_field but everytime I use it I get Array instead of any text

    I’m running out of idea and as a noobie with php, I’m really struggling

Viewing 1 post (of 1 total)

The topic ‘the_field() with checkbox as class for html’ is closed to new replies.