Support

Account

Home Forums Front-end Issues Code No Longer Working

Solved

Code No Longer Working

  • I recently changed servers and now my IF statements aren’t working and it’s just displaying both snippets.

    			<? if( get_field('post_label_status') == 'Sponsored' ){ ?>
    				<div class="post-status-label-feed">
    					<span>Sponsored Content</span>
    				</div>
    			<? } ?>
    			<? if( get_field('post_label_status') == 'Opinion' ){ ?>
    				<div class="post-status-label-feed">
    					<span>Opinion Piece</span>
    				</div>
    			<? } ?>

    It’s displaying both sponsored content and opinion pieces regardless. I have the code inside a loop and it worked previously. Any issues with PHP 7.3?

  • I don’t see anything in your code that would keep it from working. Not sure what’s going on. I would try using === instead of ==

    
    <? if( get_field('post_label_status') === 'Sponsored' ){ ?>
    				<div class="post-status-label-feed">
    					<span>Sponsored Content</span>
    				</div>
    			<? } ?>
    			<? if( get_field('post_label_status') === 'Opinion' ){ ?>
    				<div class="post-status-label-feed">
    					<span>Opinion Piece</span>
    				</div>
    			<? } ?>
    
  • Hi John,

    I tried that as well. I finally figured out the issue… the shorthand PHP tags aren’t working.

    So replacing <? with <?php worked.

  • That’ll do it, didn’t even notice those.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Code No Longer Working’ is closed to new replies.