Home › Forums › Feature Requests › get_sub_fields()
Hi,
Sometimes inside the repeater there is a need to add some logic (for example to display fields conditionally). In order to take out the logic outside the template it would be nice to have get_sub_fields() function that returns an array of all the sub fields.
So simply it’s a request for a function that works like get_fields() but inside a repeater loop.
Thanks.
Example:
At the moment the code looks like this:
<ul>
<?php while (have_rows('menu', 'options')): the_row(); ?>
<li>
<?php
$link = get_sub_field('external_link');
if (!get_sub_field('has_extarnal_link')) {
$link = get_permalink(get_sub_field('page')->ID);
}
?>
<a href="<?php echo $link ?>">
<?php the_sub_field('label'); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
If there was get_sub_fields() function it could look like this:
<?php // Template ?>
<ul>
<?php while (have_rows('menu', 'options')): the_row(); ?>
<li>
<a href="<?php echo get_menu_item_url(get_sub_fields()) ?>">
<?php the_sub_field('label'); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php
// functions.php
function get_menu_item_url($sub_fields)
{
$link = $sub_fields['external_link'];
if (!$sub_fields['has_extarnal_link']) {
$link = get_permalink(get_sub_field('page')->ID);
}
return $link;
}
?>
I’ll mark this request for the developer to take a look at when he has time.
Hi, any changes? It seems like it’s forgotten.
This feature will also help me a lot. How can I help with implementation?
The topic ‘get_sub_fields()’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.