Display custom field in archive

Hi Themeco.

I have everything set up (child theme and the rest) but I’m finding it difficult to add custom field from ACF to my archive pages.

I used this code
<?php echo get_post_meta($post->ID, 'my_field_key', true); ?>
But it didn’t work on Archive Pages. It only worked on normal pages.

I tried to implement the solution in this thread:

But it didn’t work either.

This was the solution in that thread:
<php the_field('post_html'); ?>

I replaced 'post_html' with 'my_field_key'

Please help. Thanks.

Hello @Mrbiizy,

Thanks for writing in! Please make sure that you have inserted the correct field name or else, nothing will display. To better assist you with the issue, provide us access to your site so that we can check your settings. Please create a secure note with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role

To know how to create a secure note, please check this out: How The Forum Works

![image|690x165](upload://rNac4h0SWKsmR1lTEFb4Lj32hFN.png)

Best Regards.

Thanks @ruenel. I am building on a local host.

Please take a look below. I am sure you will understand.

The image above shows the field I created with ACF. The Field Group name is “Hero Settings”. I have only one field in this field group and the name is page_description while the label is Page Description.

This is the code I am using: <?php the_field('page_description'); ?>. I tested it on a normal page and it worked perfectly just like the first code (<?php echo get_post_meta($post->ID, 'my_field_key', true); ?>) I used but it doesn’t work for the archive page. Please if you can assist me further, I will really appreciate it. Thanks.

Hello @Mrbiizy,

Can you please post the whole code contents in your archive page template? We need to check your loop and other codes found in the archive template.

Thanks.

Okay sir.

<?php

// =============================================================================
// VIEWS/INTEGRITY/IEX-ARCHIVE-HERO.PHP
// -----------------------------------------------------------------------------
// Standard <header> output for various posts.
// =============================================================================
// Hero view for archives, tags and blog page

?>

<section class="archive-hero">
  <div class="container">
    <div class="inner x-container max width">
      <div class="item-1">
        <h1 class="iex-title"><?php wp_title(''); ?></h1>
      </div>
      <div class="item-2">
        <span class="iex-text"><?php the_archive_description(); ?></span>

        <?php the_field('page_description'); ?>

      </div>
    </div>
  </div>
  <?php x_get_view( 'integrity', 'iex-hero-separator' ); ?>
</section>

Thanks :slight_smile:

Hello @Mrbiizy,

The code is correct in the archive template. I have a hunch that this template was not loaded in your archive page. Do you have a file named as archive-iex-here.php where it contents <?php x_get_view( 'integrity', 'iex-archive-hero' ); ?>? The template must be connected in some files so that the code will work.

It is good if you have uploaded your files in a web server so we can double check your child theme and other template files.

Let us know how it goes.

Hmmm… Anyways @ruenel, When I upload, I guess I’d have to open another thread.

Thanks for your time.

No problem @Mrbiizy.
Our staff will always be on standby to help you in any way we can.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.