Why are my custom fields not showing up in footer on page templates?


I have a custom field in my footer. On the home page the value shows up just fine, but on other page templates it doesn’t. I’m still pretty new to WP so I really am stuck here.

It’s this line here:

        <h3 class="text-white"><?php the_field("cta_field_title");?></h3>

If it works on the home page I assumed it would show up wherever else I call the footer. Any advice would be appreciated!

<?php

/**
 * The template for displaying the footer
 */

$nav_menu =
    wp_nav_menu(
        array(
            'theme_location'    => 'footer',
            'sort_column'            => 'menu_order',
            'container'                => false,
            'echo'                        => '0',
            'depth'                        => 1,
            'menu_class'            => 'nav__list nav__list--footer'
        )
    );

$footer_bg = get_field('footer_background_image', 'options');
$footer_bg_opacity = get_field('footer_background_opacity', 'options');
$site_name = get_field('site_title', 'options');
$address = get_field('address', 'options');
$address_link = get_field('address_link', 'options');
?>

<footer class="section section--footer">
    <div class="section--footer__header">
    <?php if( have_posts() ) : while ( have_posts() ) : the_post();?>
        <h3 class="text-white"><?php the_field("cta_field_title");?></h3>
    </div>
<?php endwhile; endif;?>
    <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>
<?php
/**
 * The page template file
 */

get_header();


if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

<h2><?php the_title();?></h2>
<p><?php the_content();?></p>

 
<?php
    endwhile;
endif;wp_reset_postdata();
get_footer();