[Support request] Outputting Advanced Custom Fields – repeater fields

Home Forums Support [Support request] Outputting Advanced Custom Fields – repeater fields

Home Forums Support Outputting Advanced Custom Fields – repeater fields

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1459592
    JUDE

    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?

    #1459820
    David
    Staff
    Customer Support

    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 ?

    #1459848
    JUDE

    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;

    ?>

    #1459863
    JUDE

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

    #1460073
    David
    Staff
    Customer Support

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

    #1460106
    JUDE

    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.

    #1460291
    Tom
    Lead Developer
    Lead Developer

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

    #1460317
    JUDE

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

    #1460354
    David
    Staff
    Customer Support

    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 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.