Cannot get ACF Content to work in Custom Template

Hello,

I have used ACF Pro fairly successfully in this website however I am now stuck.

I created a new WYSIWYG field and added it to my Custom Post Type.

I created a new Template and added the ACF PHP Code and it will not display the content and I cannot figure out why. I think this should be very straight forward. Why won’t my custom content show?

    	<?php
     			if( get_field('exphw_special_offer')) {
     				echo '<div>';
     				the_field('exphw_special_offer');
     				echo '</div>';
     			}
     	?>

Below is my Custom Template which includes the ACF code.

   	<?php
    			if( get_field('exphw_special_offer')) {
    				echo '<div>';
    				the_field('exphw_special_offer');
    				echo '</div>';
    			}
    	?>

  <?php
// =======================================================================================
// /PRO-CHILD/CUSTOM_SPECIALS.PHP  (No Container | Header, Footer)
// -----------------------------------------------------------------------------
// Special Offers Single Page Template for X-Theme Pro Renew
/* Template Name: Specials */
// =======================================================================================

get_header();

?>

  <div class="x-container max width offset">
    <div class="x-main full" role="main">

      <?php while ( have_posts() ) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
          <?php x_get_view( 'global', '_content', 'the-content' ); ?>
        </article>
		
<!-- START CPT SPECIALS -->

	SPECIALS
		
	<?php
			if( get_field('exphw_special_offer')) {
				echo '<div>';
				the_field('exphw_special_offer');
				echo '</div>';
			}
	?>

	  
<!-- END CPT SPECIALS -->

      <?php endwhile; ?>

    </div>
  </div>

<?php get_footer(); ?>

As you can see here, the content is not displaying in the new custom Template.

How do I get this content to show?

Micah

Hello Micah,

Thanks for the very detailed post information. Your template must have a name and it should be:

// TEMPLATE NAME: Specials

And then in your post, you will need to apply the post template. If you are using it to display the custom post type “custom-special”, the name of your file should also be custom-special.php. If nothing is helping, 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

Best Regards.

I renamed the file to custom-special.php.

In the page I have selected template “Specials”.

I am still not seeing my custom field.

I posted the secure note per your request.

Micah

Hey Micah,

What’s wrong with your setup is you’re displaying an ACF field that is not part of the page (Special). The Special page doesn’t have ACF data but it’s your Directory posts that have that. You should be specifying the post ID if you wish to display an ACF field outside of the post it’s added like the following code.

the_field('exphw_special_offer', 4694);

image

I’d recommend you review the ACF Pro documentation here https://www.advancedcustomfields.com/resources/

Please also note that this is the furthest we can help. We do not provide support for custom coding or theme customizations in general. We’re sorry if this wasn’t made clear.

Hope that helps and thank you for understanding.

Thanks,

Micah

You are most welcome Micah!

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