Support

Account

Home Forums ACF PRO Displaying contents from sub fields within group from outside the loop

Unread

Displaying contents from sub fields within group from outside the loop

  • Hi,

    Hope everyone are well and safe.
    I need some help on displaying contents from the sub fields that were created within the group field “customers_information“.
    The contents will be shown in the single.php page, under footer section.
    With that, my first impression is to use WP_Query, to set query to my post,

    <?php $cpost = new WP_Query(array(
    'post_type' => 'post'
    ));

    And loop through the post and the group field, like below.

    if( $cpost->have_posts() ) : while( $cpost->have_posts() ) : $cpost->the_post();
    if( have_rows('customers_information') ):
    while( have_rows('customers_information') ): the_row();
    ?>

    And then call out the sub fields (video, success_summary, podcast) like below.

    <a href="<?php the_sub_field('video') ?>" class="mfp-iframe video">
    <img src="<?php bloginfo( 'template_directory' ); ?>/images/icon_video.svg" alt="Icon">
    <p>Watch the Video</p>
    </a>
    
    <a href="<?php the_sub_field('success_summary'); ?>" target="_blank" class="case">
    <img src="<?php bloginfo( 'template_directory' ); ?>/images/icon_casestudy.svg" alt="Icon">
    <p>Read the Case Study</p>
    </a>
    
    <a href="<?php the_sub_field('podcast') ?>" target="_blank" class="podcast">
    <img src="<?php bloginfo( 'template_directory' ); ?>/images/icon_podcast.svg" alt="Icon">
    <p>Listen to the Podcast</p>
    </a>

    Unfortunately, it resulted the system to run through the whole database and display all the contents.
    However, this is not what I want.
    I only need the contents that were inserted in that individual post.
    Meaning, if I have 5 posts, the single page footer will only show either one of the post contents, and not all 5.

    Can anyone please give a helping hand to light me up with some solutions?
    Your help will be much appreciated.
    Thank you.

    Danc

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.