admin管理员组文章数量:1388105
I am loving the ACF (Advanced Custom Fields) plugin repeater field but I have two pages in my WordPress site that have sections which share exactly the same data.
Obviously one of the key aspects of a CMS is that when such a situation as the one above arises, the client should only have to update that shared data in one place.
I'm wondering how I can do this though? I have found the below:
<?php
$include = get_pages('include=120' );
$content = apply_filters('the_content' ,$include[0]->post_content);
echo $content;
?>
This works for 'the_content' but I am not sure how to substitute it for my repeater field data which looks like this:
<?php
if( get_field('treatments' ) ): ?>
<?php
$i = 0;
while( has_sub_field('treatments' ) ):
$i++;
?>
<div class="treatments" id="treatment-<?php echo $i; ?>">
<img src="<?php the_sub_field('image' ); ?>" />
<?php the_sub_field('description' ); ?>
<a href="<?php the_sub_field('link' ); ?>">Read More ></a>
</div> <!-- treatments -->
<?php endwhile; ?>
<?php endif; ?>
I am loving the ACF (Advanced Custom Fields) plugin repeater field but I have two pages in my WordPress site that have sections which share exactly the same data.
Obviously one of the key aspects of a CMS is that when such a situation as the one above arises, the client should only have to update that shared data in one place.
I'm wondering how I can do this though? I have found the below:
<?php
$include = get_pages('include=120' );
$content = apply_filters('the_content' ,$include[0]->post_content);
echo $content;
?>
This works for 'the_content' but I am not sure how to substitute it for my repeater field data which looks like this:
<?php
if( get_field('treatments' ) ): ?>
<?php
$i = 0;
while( has_sub_field('treatments' ) ):
$i++;
?>
<div class="treatments" id="treatment-<?php echo $i; ?>">
<img src="<?php the_sub_field('image' ); ?>" />
<?php the_sub_field('description' ); ?>
<a href="<?php the_sub_field('link' ); ?>">Read More ></a>
</div> <!-- treatments -->
<?php endwhile; ?>
<?php endif; ?>
Share
Improve this question
edited Feb 25, 2013 at 19:41
user26607
asked Feb 25, 2013 at 19:12
JohnnyJohnny
2151 gold badge3 silver badges6 bronze badges
1 Answer
Reset to default 1The ACF functions accept a second argument which is the ID of the page you wish to retrieve the fields from. See the code examples in documentation.
$page_id = 120;
if( get_field( 'treatments', $page_id ) ):
while( has_sub_field( 'treatments', $page_id ) ):
// the_sub_field and get_sub_field don't need a post id parameter
the_sub_field('image' );
the_sub_field('description' );
endwhile;
endif;
本文标签: How to share repeated fields across multiple pages
版权声明:本文标题:How to share repeated fields across multiple pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744492510a2608821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论