Code being called multiple times

If you go to this dev site

And look at the page source you will see that this is called 3 times

/*These styles are dynamically generated from the header post using ACF color picker fields */

At the top of the document and this code in the bottom of the footer is being called 3 times. Well just “OUR OFFICE IS LOCATED AT:” is.

Any idea what could be causing this?

       <section id="FooterOfficeSec" class="col-lg-3">

                        while ( have_posts() ) : the_post(); ?>
                      			<ul id="OfficeFooterLocation" class="list-unstyled FooterFontColor"> 
                                			<li id="OfficeLocated"> OUR OFFICE IS LOCATED AT: </li>
                                            <li><?php the_field('footer_address') ?></li>
                                            <li><?php the_field('footer_city_and_state') ?> </li>
                        <?php endwhile; ?>
                       <?php wp_reset_query(); ?>  

Is the code that is being hit 3 times part of a function? If it is, try using debug_backtrace() ( to see what’s hitting the function

it isn’t part of a function. I’ve figured out part of the issue. For some reason it is displaying the content for every post that exists. I added a 4th and 5th post and it displayed the content 4 and 5 times respectively.

If I understand the problem, you need to move the unordered list to after the endwhile.

1 Like

Since you do understand the problem then you did help me correct it! #Nice I would tip on here if it were possible.

It worked for the footer issue, but not for the header. Is there a way to query without a while loop?

  //This post id must be accurate for the post.  There may be a conflict with this when importing a database
		  while ( have_posts() ) : the_post(); ?>

/*These styles are dynamically generated from the header post using ACF color picker fields */

.CTAColorFont {
	color:<?php the_field('cta_color'); ?>;		
.CTAColorBackground {
	background-color:<?php the_field('cta_color'); ?>;		
.BaseColorFont {
	color:<?php the_field('base_color'); ?>;		
.BaseColorBackground {
	background-color:<?php the_field('base_color'); ?> !important;		
.LightAccentColorFont {
	color:<?php the_field('light_accent_color'); ?>;		
.LightAccentColorBackground {
	background-color:<?php the_field('light_accent_color'); ?> !important;
.DarkAccentColorFont {
	color:<?php the_field('dark_accent_color'); ?>;
.DarkAccentColorBackground {
	background-color:<?php the_field('dark_accent_color'); ?>;		
.FooterDarkColorFont {
	color:<?php the_field('footer_dark_color'); ?>;		
.FooterDarkColorBackground {
	background-color:<?php the_field('footer_dark_color'); ?>;
button, input[type="button"], input[type="reset"], input[type="submit"] {

border-color: transparent;
background-color:<?php the_field('cta_color'); ?> !important;

<?php endwhile; ?> <?php wp_reset_query(); ?>

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