Skip to main content
2 of 2
Added paragraphs to code for readability. Markdown in text. Removed unrelated content.
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

Custom Meta Box If Else Statement

I have created a custom meta box for posts and I need to display said data. I have been using the below method to display the data, But I am in need of a slightly different solution.

<a href="<?php echo esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text4', true ) ); ?>">
    <img src="<?php echo esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text3', true ) ); ?>" alt="" onerror="this.style.display='none'"/>
</a>

What I need is a way to do a IF/Else statement such is. If my_meta_box_text3 exists echo that, else echo this.

Phil Hoyt
  • 127
  • 1
  • 1
  • 9