Home › Forums › General Issues › Repeaters have_rows has no value…
Having some REPEATER field issues. The “have_rows” function doesn’t see to be working. Below is my code, with some comment tags for testing. The first comment just outputs “<!– side_feature: –>, so I know that there is some problem with getting the values. The rest of the code doesn’t run because the next IF statement doesn’t register any value.
I checked the field names, and they are all correct (so I don’t see any typo issue). There are definitely values entered when I EDIT the page – So, the issue isn’t in the PAGE administration.
I also checked and saw that I am running the most recent versions of the plugin, and WordPress.
Any help is appreciated. Thanks!
<div class="sidebox">
<!-- side_feature: <?php if( have_rows('side_feature') ) { echo 'yes'; } ?> -->
<?php
if( have_rows('side_feature') ):
?><!-- Feature --><?php
while( have_rows('side_feature') ): the_row();
$side_feature_txt = get_sub_field('side_feature_txt');
$side_feature_url = get_sub_field('side_feature_url');
$side_feature_img_field = get_sub_field('side_feature_img');
$size = "medium"; // (thumbnail, medium, large, full or custom size)
$side_feature_img = wp_get_attachment_image_src( $side_feature_img_field, $size );
?>
<div class="side-feat">
<?php if($side_feature_txt!='') { ?>
<?php if($side_feature_url!='') { ?><a href="<?php echo $side_feature_url; ?>"><?php } ?>
<div class="side-feat-txt"><?php echo $side_feature_txt; ?></div>
<div class="side-feat-txtbox"></div>
<?php if($side_feature_url!='') { ?></a><?php } ?>
<?php } ?>
<?php if($side_feature_img!='') { ?>
<?php if($side_feature_url!='') { ?><a href="<?php echo $side_feature_url; ?>"><?php } ?>
<div class="side-feat-img" style="background:url('<?php echo $side_feature_img[0]; ?>');">
<!--
<?php if($side_feature_url!='') { ?><a href="<?php echo $side_feature_url; ?>"><?php } ?>
<img src="<?php echo $side_feature_img[0]; ?>" width="360" height="150" />
<?php if($side_feature_url!='') { ?></a><?php } ?>
-->
</div>
<?php if($side_feature_url!='') { ?></a><?php } ?>
<?php } ?>
</div><!-- END .side-feat -->
<?php
endwhile; // End While
endif;
?>
</div>
Hi @jabbamonkey
Can you please debug your data like so:
<?php
echo '<pre>';
print_r( get_field('side_feature') );
echo '</pre>';
die; ?>
What do you see?
Is it possible that ACF does not know which post to load the data from?
Where are you using this code?
Does get_the_ID()
return the correct post’s ID in the same area as your code?
Thanks
E
The output is only
<pre></pre>
I know it’s not an ID issue, since the page is loading other values from ACF on the page.
I also used get_post_meta to see the values in the database for side_feature …
`[side_feature_0_side_feature_img] => Array
(
[0] => 50633
)
[_side_feature_0_side_feature_img] => Array
(
[0] => field_530b8c7eb5ff4
)
[side_feature_0_side_feature_txt] => Array
(
[0] => Ridgewood
)
[_side_feature_0_side_feature_txt] => Array
(
[0] => field_530b8c9cb5ff5
)
[side_feature_0_side_feature_url] => Array
(
[0] => http://www.somewhere.com/2
)
[_side_feature_0_side_feature_url] => Array
(
[0] => field_530b8cb5b5ff6
)
[side_feature] => Array
(
[0] => 2
)
[_side_feature] => Array
(
[0] => field_530b8c5eb5ff3
)`
Hi @jabbamonkey
The data definitely exists thanks to your debug above.
Is there anything special about your code that I am not aware of?
Is this all in an action / filter? Or a normal page template file?
Do you have any filters running on the repeater field which could be clearing the value.
Thanks
E
Discovered why our issue is happening. It’s because we call register_field_group() on the backend but not the frontend so the acf-field cpt entry is not detected.
in /api/api-field.php in the _acf_get_field_by_key() method it users a get_posts query that looks for the custom field, but it’s not added in.
So get_rows for repeater fields depends on the custom fields being in the db, where as get_field() does not.
The topic ‘Repeaters have_rows has no value…’ 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.