0

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.enter image description here

  • 1
    did you update php? Maybe try changing <h2>color chart</h2 <? to<h2>color chart</h2 <?php – rudtek Feb 13 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 Feb 13 at 20:22
  • done. Thanks, let me know if there's anything else. – rudtek Feb 13 at 21:03
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.