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

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>">
    <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_text3my_meta_box_text3 exists echo thatecho that, else echo thisecho this. Any help would be much appreciated, thanks!

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. Any help would be much appreciated, thanks!

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.

Source Link
Phil Hoyt
  • 127
  • 1
  • 1
  • 9

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. Any help would be much appreciated, thanks!