描述
参数
has_sub_field($field_name,$post_id);
$字段名 (字符串) (必需) 要检索的Repeater或Flexible Content字段的名称。 例如“gallery_images” $帖子id (混合) (可选) 保存值的帖子ID。 默认为当前帖子。
返回
更改日志
版本4.3.0中已弃用
示例
循环通过中继器字段
<? php if(get_field('gallery_images')):?> <? php while(has_sub_field('gallery_images')):?> <img src=“<?php the_sub_field('image');?>”alt=“>?php the _sub_feld('alt');”/> <? php endwhile;?> <? php-endif;
循环浏览“灵活内容”字段
<? php while(has_sub_field(“内容”)):?> <? php if(get_row_layout()==“段落”):?> <div> <? php the_sub_field(“内容”);?> </div> <? php elseif(get_row_layout()==“文件”):?> <div> <a href=“<?php the_sub_field(”file“);?>”><? php the_sub_field(“名称”);?></ a> </div> <? php elseif(get_row_layout()==“featured_posts”):?> <div> <h2><? php the_sub_field(“标题”);?></ 氢气> <? php the_sub_field(“内容”);?> <? php-if(get_sub_field(“posts”)):?> <ul> <? php foreach(get_sub_field(“posts”)作为$p):?> <li><a href=“<?php echo get_permalink($p->ID);?>”><? php echo get_the_title($p->ID);?></ a></li> <? php endforeach;?> </ul> <? php-endif;?> </div> <? php-endif;?> <? php endwhile;?>
循环访问嵌套的Repeater字段
<? php if(get_field(“父转发器”):?> <? php while(has_sub_field('父转发器')):?> <div> <? php if(get_sub_field('child_reporter')):?> <ul> <? php while(has_sub_field('child_reporter')):?> <li><? php子字段(“项目”);?></ li> <? php endwhile;?> </ul> <? php-endif;?> </div> <? php endwhile;?> <? php-endif;
循环访问嵌套的Repeater字段(来自另一个$post ID)
<? php if(get_field(“父转发器”,123)):?> <? php while(has_sub_field('parent_reporter',123)):?> <div> <? php(电话) if(获取子字段(“儿童中继器”):?> <ul> <? php while(has_sub_field('child_reporter')):?> <li><? php子字段(“项目”);?></ li> <? php endwhile;?> </ul> <? php-endif;?> </div> <? php endwhile;?> <? php-endif;