高级自定义字段True / False字段无效

时间:2017-02-12 07:45:31

标签: php advanced-custom-fields

<?php if( have_rows('team_members') ): ?>
    <?php while( have_rows('team_members') ): the_row(); ?>
        <div class="team-member-section">   
            <div class="container">
                <?php if( get_row_layout() == 'team_members' ): ?>
                    <section class="team-member-section">                                   
                        <?php 
                            $team_title = get_sub_field('team_title');
                            $team_member = get_sub_field('team_member');
                            $description = get_sub_field('description');
                        ?>
                        <div class="team-title">
                            <?php echo $team_title; ?>
                        </div>
                         <?php if( $team_member ): ?>
                            <?php if ( get_field('has_description') == 'yes') : ?>
                                <?php echo 'has_description'; ?>
                            <?php  else : ?>
                                <?php echo 'has_no_description'; ?>
                            <?php endif; ?>  
                        <?php endif; ?>
                    </section>
                <?php endif; ?>
            </div>
        </div>
    <?php endwhile; ?>
<?php endif; ?>

它只显示值&#34; has_no_description&#34;,为什么我的真/假字段不起作用以及如何使其工作,以便显示两种情况。

enter image description here

更新

<?php if( have_rows('team_members') ): ?>
<?php while( have_rows('team_members') ): the_row(); ?>
    <div class="team-member-section">   
        <div class="container">
            <?php if( get_row_layout() == 'team_members' ): ?>
                <section class="team-member-section">                                   
                    <?php 
                        $team_title = get_sub_field('team_title');
                        $team_member = get_sub_field('team_member');
                        $description = get_sub_field('description');
                    ?>
                    <div class="team-title">
                        <?php echo $team_title; ?>
                    </div>
                     <?php if( $team_member ): ?>
                        <?php if ( get_field('has_description') ) : ?>

                        <?php foreach( $team_member as $post): ?>
                            <?php setup_postdata($post); ?>
                                <div class="col-sm-4">
                                    <div class="team-member">
                                        <div class="member-img">
                                            <?php the_post_thumbnail(); ?>
                                        </div>
                                        <h4><?php the_title(); ?></h4>
                                        <?php the_content(); ?>
                                        <?php echo "Has description"; ?>
                                        <?php $overlay_text = get_field('overlay_text'); ?>

                                        <?php if($overlay_text != ''): ?>
                                            <div class="overlay-text">
                                                <p><?php echo $overlay_text; ?></p>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php wp_reset_postdata(); ?>
                        <?php endforeach; ?>
                        <?php  else : ?>
                        <?php foreach( $team_member as $post): ?>
                            <?php setup_postdata($post); ?>
                                <div class="col-sm-4">
                                    <div class="team-member">
                                        <div class="member-img">
                                            <?php the_post_thumbnail(); ?>
                                        </div>
                                        <h4><?php the_title(); ?></h4>
                                        <?php the_content(); ?>
                                        <?php echo "Doesn not have description"; ?>
                                        <?php $overlay_text = get_field('overlay_text'); ?>

                                        <?php if($overlay_text != ''): ?>
                                            <div class="overlay-text">
                                                <p><?php echo $overlay_text; ?></p>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>


                            <?php wp_reset_postdata(); ?>
                         <?php endforeach; ?>

                        <?php endif; ?>  
                    <?php endif; ?>
                </section>
            <?php endif; ?>
        </div>
    </div>
<?php endwhile; ?>

我发布了我的整个代码。 我认为这里的问题是该字段&#39; has_description&#39;仅在&#34; Team&#34;上展示自定义帖子类型以及该字段返回null的原因,但我不确定。有人能让它发挥作用吗?

1 个答案:

答案 0 :(得分:1)

<?php if( have_rows('team_members') ): ?>
<?php while( have_rows('team_members') ): the_row(); ?>
    <div class="team-member-section">   
        <div class="container">
            <?php if( get_row_layout() == 'team_members' ): ?>
                <section class="team-member-section">                                   
                    <?php 
                        $team_title = get_sub_field('team_title');
                        $team_member = get_sub_field('team_member');
                        $description = get_sub_field('description');
                    ?>
                    <div class="team-title">
                        <?php echo $team_title; ?>
                    </div>
                     <?php if( $team_member ): ?>
                        <?php foreach( $team_member as $post): ?>
                            <?php if ( get_field('has_description') ) : ?>
                            <?php setup_postdata($post); ?>
                                <div class="col-sm-4">
                                    <div class="team-member">
                                        <div class="member-img">
                                            <?php the_post_thumbnail(); ?>
                                        </div>
                                        <h4><?php the_title(); ?></h4>
                                        <?php the_content(); ?>
                                        <?php echo "Has description"; ?>
                                        <?php $overlay_text = get_field('overlay_text'); ?>

                                        <?php if($overlay_text != ''): ?>
                                            <div class="overlay-text">
                                                <p><?php echo $overlay_text; ?></p>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php wp_reset_postdata(); ?>
                            <?php  else : ?>
                                <div class="col-sm-4">
                                    <div class="team-member">
                                        <div class="member-img">
                                            <?php the_post_thumbnail(); ?>
                                        </div>
                                        <h4><?php the_title(); ?></h4>
                                        <?php the_content(); ?>
                                        <?php echo "NOOOOOOO Description"; ?>
                                        <?php $overlay_text = get_field('overlay_text'); ?>

                                        <?php if($overlay_text != ''): ?>
                                            <div class="overlay-text">
                                                <p><?php echo $overlay_text; ?></p>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php endif; ?>  
                        <?php endforeach; ?>
                    <?php endif; ?>
                </section>
            <?php endif; ?>
        </div>
    </div>
<?php endwhile; ?>

它是这样的,我在foreach中移动了真/假<?php if ( get_field('has_description') ) : ?>字段,因为true / false字段属于团队自定义帖子类型,离开循环将始终使其为NULL