- This topic has 8 replies, 3 voices, and was last updated 3 years, 6 months ago by David.
-
AuthorPosts
-
September 26, 2020 at 2:35 am #1459592JUDE
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?
September 26, 2020 at 6:55 am #1459820DavidStaffCustomer SupportHi there,
GP doesn’t interfere how code is added – WP might do if it deems in invalid.
What happens when you add your code ?September 26, 2020 at 7:15 am #1459848JUDEThis 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;?>
September 26, 2020 at 7:29 am #1459863JUDEAnd to answer your question, what do I get on the page when I add the code – the answer is nothing.
September 26, 2020 at 8:46 am #1460073DavidStaffCustomer SupportI am not big ACF user – but how are the repeater fields added ? Are they from an options page?
September 26, 2020 at 9:00 am #1460106JUDEYou 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.September 26, 2020 at 1:27 pm #1460291TomLead DeveloperLead DeveloperYour code itself looks ok. Nothing is output at all? Are you sure the fields hold values?
September 26, 2020 at 2:15 pm #1460317JUDEI solved it – it was rogue quote marks – sort of curly rather than straight. I’m an idiot!
September 26, 2020 at 3:06 pm #1460354DavidStaffCustomer SupportDamn 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 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.