I'm trying to retrieve the values of checkboxes in a custom post type.
My complete function:

        function getTeam() {

            global $post;
            $team = new WP_Query();
            $workshops = get_field('workshops');

            if ($team->found_posts > 0) {
                echo '<ul>';
                    while ($team->have_posts()) {
                        $listTeam = '<li>';
                        $listTeam .= '<a href="#" class="js-modal">';
                        $listTeam .= '<figure class="profile-img">';
                        $listTeam .= '<img src="' . get_field('profile-image') . '" alt="">';
                        $listTeam .= '<figcaption><span>Bekijk profiel</span></figcaption>';
                        $listTeam .= '</figure>';
                        $listTeam .= '</a>';
                        $listTeam .= '<article class="profile-bio">';
                        $listTeam .= '<div class="details">';
                        $listTeam .= '<h3>' . get_field('name') . '</h3>';
                        $listTeam .= '<h4>Workshop(s)</h4>';
                        $listTeam .= '<ul class="workshops">';
                        if ($workshops) {
                            foreach($workshops as $workshop) {
                                $listTeam .= '<li>' . $workshop . '</li>';
                        $listTeam .= '</ul>';
                        $listTeam .= '</div>';
                        $listTeam .= '<p>' . get_field('biography') . '</p>';
                        $listTeam .= '</article>';
                        $listTeam .= '</li>';
                        echo $listTeam;
                echo '</ul>';
            } else {
                echo '<p>No team members found</p>';

            var_dump($workshops, $workshop);


I created the foreach loop with the help of the ACF checkbox documentation and as far as I know there are no errors in that.
But I get for $workshops bool(false) and for $workshop NULL returned.
How can I troubleshoot this the best to see where this goes wrong?
I tried http://php.net/manual/en/language.types.boolean.php but that doesn't say anything (yet) to me :)

Edited by gentlemedia

1 Year
Discussion Span
Last Post by gentlemedia

Have you looked at var_dump($workshops) just after the get_field() call? If it's false there, you might need to include the id. And if that's the case, this should go inside your while loop.
$workshops = get_field('workshops', get_the_id() );

Edited by Jeff_8


Is this valid? I.d do it like this. Apologies on moblile...

$args = array(
'post_type' => 'coaches'
$query = new WP_Query( $args );

Thanks! The var $workshops = get_field('workshops'); needed to go inside while loop.
That's why I also probably couldn't retieve the $image Object that I had as an issue in a previous thred of mine. I had that var outside the while loop too.

It's working so I assume it's valid :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.