mercredi 24 juin 2015

Correct syntaxing of php if-statement

I'm having some trouble with the if-statement in the output section here. The intention is to show only the lecturers who has display == 'yes'. But for some reason it doesn't display any lecturers at all, when I remove the if statement it shows all of them. Am I using the wrong syntax on the if-statement?

       $args = array(
                'post_type'        => 'lecturer',
                'post_status'      => 'publish',
                'suppress_filters' => true,
                'orderby'          => 'menu_order',
                'order'            => 'ASC',

        );

        $lecturer_array = get_posts( $args );

        $output = '<div class="lecturer-container">';

        foreach ( $lecturer_array as $lecturer ) : setup_postdata( $lecturer );

            $display = get_post_meta($lecturer->ID, 'display', true);
            $name = get_post_meta($lecturer->ID, 'name', true);
            $department = get_post_meta($lecturer->ID, 'department', true);
            $description = get_post_meta($lecturer->ID, 'description', true);
            $email = get_post_meta($lecturer->ID, 'email', true);
            $twitter = get_post_meta($lecturer->ID, 'twitter', true);
            $permalink = get_permalink( $lecturer->ID );

            $image = get_post_meta($lecturer->ID, 'lecturer_image', true);
            $img = Media::get($image[0], 'full');
            $siteUrl = site_url();
            $imgPath = $siteUrl . $img['src'][0];
            if ($display == 'yes'){


            $output .= '<div class="lecturer-item">';
            $output .= '    <a class="lecturer-image" href="'. $permalink .'">';
            $output .= '        <img src="' . $imgPath .'">';
            $output .= '    </a>';
            $output .= '    <div class="lecturer-details">';
            $output .= '        <div class="title">' . $department .'</div>';
            $output .= '        <a class="name" href="'. $permalink .'">' . $name .'</a>';
            $output .= '        <hr>';
            $output .= '        <div class="contact"><ul><li><a href="mailto:' . $email .'">email</a></li><li><a href="' . $twitter .'">twitter</a></li></ul></div>';
            $output .= '    </div>';

            $output .= '    <p class="lecturer-description">' . $description . '</p>';
            $output .= '</div>';

            $output .= '<div class="lecturer-spacer"></div>';
            }


        endforeach;
        $output .= '</div><!-- LECTURER CONTAINER -->';
        wp_reset_postdata();

    return $output;

}

Aucun commentaire:

Enregistrer un commentaire