Site logo

Archived topic

Outputting Advanced Custom Fields - repeater fields

8 replies · Started by JUDE on September 26, 2020

Viewing posts 1–9 of 9

So, thanks to your help last week, I now know how to output Advanced Custom Fields into a Hook element.
But now I have a Repeater Field and I'm stuck again.
I did something similar on another WordPress site and added code directly to the template - see below:
<?php

// check if the repeater field has rows of data
if( have_rows(‘accolades’) ):

// loop through the rows of data
while ( have_rows(‘accolades’) ) : the_row();

// display a sub field value
echo '

' . get_sub_field(‘review’) . '
<p class="text-muted">' . get_sub_field('author') . '</p>

';
endwhile;

else :

// no rows found

endif;

?>

However, I'm aware that Generatepress writes (parses?) the code slightly differently, but I can't work out how to do it.

Can you help?

Hi there,

GP doesn't interfere how code is added - WP might do if it deems in invalid.
What happens when you add your code ?

This is the wole page of code from the Hook. Everything else outputs, apart from the 'accolades' repeater field.

<?php
$custom_field = get_post_meta( get_the_ID(), 'ticket', true );

echo $custom_field;
?>

<br>
Release year: <?php
$custom_field = get_post_meta( get_the_ID(), 'film_year', true );

echo $custom_field;
?>
<br>
Length: <?php
$custom_field = get_post_meta( get_the_ID(), 'film_length', true );

echo $custom_field;
?>
<br>

<?php
$custom_field = get_post_meta( get_the_ID(), 'film_description', true );

echo $custom_field;
?>

<br>
<?php
$custom_field = get_post_meta( get_the_ID(), 'awards', true );
echo $custom_field;
?>

<?php

// check if the repeater field has rows of data
if( have_rows(‘accolades’) ):

// loop through the rows of data
while ( have_rows(‘accolades’) ) : the_row();

// display a sub field value
echo '

' . get_sub_field(‘review’) . '
<p class="text-muted">' . get_sub_field('author') . '</p>

';
endwhile;

else :

// no rows found

endif;

?>

<?php
$custom_field = get_post_meta( get_the_ID(), 'trailer', true );
echo $custom_field;

?>

And to answer your question, what do I get on the page when I add the code - the answer is nothing.

I am not big ACF user - but how are the repeater fields added ? Are they from an options page?

You add the custom fields in the Advanced Custom Fields plugin, then you output them in the Hook so they display on the pages where you want them to show.
I'm going to give you login details so you can have a look.

Your code itself looks ok. Nothing is output at all? Are you sure the fields hold values?

I solved it - it was rogue quote marks - sort of curly rather than straight. I'm an idiot!

Damn those curly quotes - Glad to hear you found the issue.

As a note - when adding code in the forum, if you highlight the code and click the code button it will maintain its formatting - may help us spot those pesky quotes :)

This archived topic is closed to new replies.