Reputation: 553
This seems really simple, but I can't get it to work. All I want is to display a heading that is stored as a custom field (it's the h3 tag). I'm using it another place in my code and it works, but not in the footer. Do ACF only work in some areas and not others?
<footer class="section section--footer">
<div class="section--footer__header">
$post_id = get_queried_object_id();
<h3 class="text-white"><?php echo the_field("cta_field_title",$post_id);?></h3>
</div>
<form action="#" class="section--footer__form">
<div class="section--footer__input-box center">
<label for="name"></label>
<input type="text" id="name" placeholder="name" class="input">
<label for="email"></label>
<input type="text" id="email" placeholder="email address" class="input">
</div>
<div class="button__box center">
<a href="#" class="button">Submit</a>
</div>
</form>
<div class="section--footer__links">
<?php wp_nav_menu(array(
"theme_location" => "footer",
"menu" => "desktop",
"menu_class" => "section--footer__links"
)) ?>
<?php wp_nav_menu(array(
"theme_location" => "social",
"menu" => "desktop",
)) ?>
</div>
</footer>
<?php wp_footer() ?>
</body>
</html>
Upvotes: 1
Views: 2624
Reputation: 14312
When you are using ACF functions to get the field value outside the Wordpress "loop", you need to pass the post id into the function as the 2nd argument, e.g.
$post_id = get_queried_object_id(); // gets the id of the current page/post
the_field("cta_field_title", $post_id);
(FYI, you don't need to use echo with the_field
... the function displays the value already. However you do need to use it with get_field
, get_fields
etc).
So your footer will look something like this:
<footer class="section section--footer">
<div class="section--footer__header">
<?php $post_id = get_queried_object_id(); /* get the current page/post id */ ?>
<h3 class="text-white"><?php the_field("cta_field_title", $post_id);?></h3>
</div>
// rest of your code here
</footer>
References:
Upvotes: 1