php - Loop stopped working

admin2025-06-03  2

I have a huge issue and I broke my had trying to find the correct solution. I have a following loop code. This loop is inside my page-product.php file:

<?php 
    $terms = get_the_terms( get_the_ID(), 'colour' );
    if ( $terms && ! is_wp_error( $terms ) ) :
?>
<section class="colour__chart">
    <div class="container">
        <div class="row">
            <div id="color-chart">
               <h2>Colour Chart</h2>
                <?
            $terms = get_the_terms( get_the_ID(), 'colour' );
if( $terms && ! is_wp_error( $terms ) ){
    foreach( $terms as $term ){

        echo get_field( 'name', 'colour_' . $term->term_id ); 

        echo '<div class="col-md-2 col-sm-4 col-xs-4 text-center">';
        echo '<div class="color-chart__item" style="background-color:' . get_field( 'colour_acf', 'colour_' . $term->term_id ) . '"></div>';
        echo '<p>' . $term->name . '</p>' ;
        echo '</div>' ;
    }
}
            ?>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

and everything worked great before today. Suddenly the loop stopped working and instead of its correct displaying in the front-end I see only this text:

'; echo '
'; echo '
' . $term->name . '

' ; echo '

I've attached a screenshot also. Would appreciate any help.

I have a huge issue and I broke my had trying to find the correct solution. I have a following loop code. This loop is inside my page-product.php file:

<?php 
    $terms = get_the_terms( get_the_ID(), 'colour' );
    if ( $terms && ! is_wp_error( $terms ) ) :
?>
<section class="colour__chart">
    <div class="container">
        <div class="row">
            <div id="color-chart">
               <h2>Colour Chart</h2>
                <?
            $terms = get_the_terms( get_the_ID(), 'colour' );
if( $terms && ! is_wp_error( $terms ) ){
    foreach( $terms as $term ){

        echo get_field( 'name', 'colour_' . $term->term_id ); 

        echo '<div class="col-md-2 col-sm-4 col-xs-4 text-center">';
        echo '<div class="color-chart__item" style="background-color:' . get_field( 'colour_acf', 'colour_' . $term->term_id ) . '"></div>';
        echo '<p>' . $term->name . '</p>' ;
        echo '</div>' ;
    }
}
            ?>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

and everything worked great before today. Suddenly the loop stopped working and instead of its correct displaying in the front-end I see only this text:

'; echo '
'; echo '
' . $term->name . '

' ; echo '

I've attached a screenshot also. Would appreciate any help.

Share Improve this question asked Feb 13, 2019 at 19:39 JamdevJamdev 1175 bronze badges 3
  • 1 did you update php? Maybe try changing <h2>color chart</h2 <? to<h2>color chart</h2 <?php – rudtek Commented Feb 13, 2019 at 20:12
  • @rudtek yeah that helped! Thanks a lot my friend. Please, post it as a separate comment so I could mark it as a solved. – Jamdev Commented Feb 13, 2019 at 20:22
  • done. Thanks, let me know if there's anything else. – rudtek Commented Feb 13, 2019 at 21:03
Add a comment  | 

1 Answer 1

Reset to default 2

While <? was once a valid php opener, you should be using <?php.

Try changing this line:

           <h2>Colour Chart</h2>
            <?

to

           <h2>Colour Chart</h2>
            <?php

That should allow the php to be read correctly.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748910188a314736.html

最新回复(0)