Home Forums General Issues Using ACF to fill a custom archive loop?


Using ACF to fill a custom archive loop?

  • Caveat: I’m just getting started with WordPress, so I might be missing something super-basic here.

    I want to use ACF to auto-fill a custom archive page template. In a “services” post type, I have a field called “services_overview” and I want that field to show in a list of services. To lessen work for my client, I want to make a loop that will list the service titles (which WordPress automatically does) along with each service post’s overview.

    In the documentation, it says I can call custom field values from another page, but it seems to me that that other page has to be specified by post ID. How would it work if it was an archive page, where the values are scattered among different pages, and new ones might be added in the future? Would I have to specify them and forget about the loop idea?

  • Hi @anitaycheng

    The WP archive page loops through x amount of posts and for each post, it sets up the $post object so you can use functions like the_title and the_content.

    This works the same as get_field / the_field. Within the loop, ACF will load data from the current $post, so you don’t need to worry about ‘loading from another page’


  • Thanks for the clarification, @elliot It turns out what I was doing works on my local computer running MAMP, but it fails when I try to transfer it to a live site. In fact, I can’t call any ACF fields on my pages at all.

    I have WP multisite running on both configurations, with the same plugins running on both as well, and the same functions.php file, obviously. I have Hostgator as a hosting server, and I don’t know if there’s something on their end which is interfering with ACF.

    Here is a piece of code that results in the correct ACFs being called while on MAMP, but calls nothing while on the live site:

    add_action( 'genesis_post_content', 'caremaestro_post_content', 14 );
    function caremaestro_post_content() { 
    if ( is_post_type ('programs'|| 'services' ) && !is_archive() &&!is_page (array(47,104,77,92,118)) &&! is_post_type ('press') )  { ?>
    <img class="infoicon" src="<?php the_field('informative_icon', 'programs'); ?>" width="100%" />
    <div class="descriptive-headline"><p><?php the_field('short_descriptive_headline','programs'); ?></p></div>
    <div class="description-full"><p><?php the_field('description','programs'); ?></p></div>
    <img class="diagram" src="<?php the_field('diagram'); ?>" width="100%" />
    <div class="features"><h4>Features</h4><?php the_field('features','programs'); ?></div>
    <div class="benefits"><h4>Benefts</h4><?php the_field('benefits','programs'); ?></div>

    Actually, on MAMP I didn’t even have to use the $post_ID parameter, and it still worked. But on the live site, with the $post_ID parameter, nothing is populated. I still get the h4 headlines though, so I know the PHP is working. There’s just nothing between the <p> tags. I’m just befuddled over what could be interfering.


  • Hi @anitaycheng

    There are a few issue with your ACF code.
    You are misusing the the_field function parameters.

    You are passing through 2 parameters which are both strings. Can you please explain what this is for? Can you also read the the_field documentation to better understand the parameters available?


  • Oh wow, that was a really stupid mistake on my part. It was late at night and I was just trying whatever I could and forgot what version I was copy-pasting over.

    Basically, my live site wasn’t calling the custom fields while my local install was.

    I did manage to fix it. Something in my live install was interfering, it looks like. I deleted the WordPress install on my live server and reinstalled it manually (instead of using the Fantastico script provided by Hostgator), then used a Migrating DB plugin to push the local database exactly the way it is to the live server, and all my custom field calls work now. Something just got a little messed up along the way the first time, me thinks…

    Thanks for your patience and your quick response!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Using ACF to fill a custom archive loop?’ is closed to new replies.