Php 高级自定义字段真/假字段不工作
它只显示值“has_no_description”,为什么我的真/假字段不起作用,以及如何使其起作用,以便显示这两种情况 更新:Php 高级自定义字段真/假字段不工作,php,advanced-custom-fields,Php,Advanced Custom Fields,它只显示值“has_no_description”,为什么我的真/假字段不起作用,以及如何使其起作用,以便显示这两种情况 更新: <?php if( have_rows('team_members') ): ?> <?php while( have_rows('team_members') ): the_row(); ?> <div class="team-member-section"> <div
<?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; ?>
我发布了我的全部代码。
我认为这里的问题是“has_description”字段只显示在“Team”自定义帖子类型上,这就是该字段返回null的原因,但我不确定。有人能让它工作吗?
<?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; ?>
它的工作原理是这样的,我在foreach中移动了true/false
字段,因为true/false字段属于团队自定义的post类型,处于循环之外将始终使其为空,这里我使用的字段“has\u description”has\u description是true/false类型,并显示为复选框。unfotunaly否,它只显示else分支。您能否显示var\u dump(get\u字段('has\u description'))的输出代码>?输出为空
<?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; ?>