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();
            $team->query('post_type=coaches');
            $workshops = get_field('workshops');

            if ($team->found_posts > 0) {
                echo '<ul>';
                    while ($team->have_posts()) {
                        $team->the_post();
                        $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>';
                wp_reset_postdata();
            } 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 :)

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() );

Member Avatar for diafol
 $team->query('post_type=coaches');

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

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

@jeff_8
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.

@diafo;
It's working so I assume it's valid :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.