Support » Fixing WordPress » how to get_post_meta and if else statement

Viewing 3 replies - 1 through 3 (of 3 total)
  • Would it no be as easy just to test the metadata, instead of using a function?

    By looking at the call it is already inside the loop, so this would be quicker and less code than using another function!

    if( get_post_meta( the_ID(), 'video', true ) ) {
    	echo get_post_meta( the_ID(), 'video', true );
    } else {
        if( has_post_thumbnail() ) the_post_thumbnail('100%-thumb');





    Forum Moderator

    if(function_exists('get_custom_field_data')) is of course always true as long the function’s code is either in a plugin or in functions.php of your theme.

    possibly try to check if the ‘video’ custom field exists for the post:

    <?php if( get_custom_field_data('video') ) {
          get_custom_field_data('video', true);
     }  else {
     }  ?>

    Thanks YOU!

    I thought that the if statement was always true. Due to my lack in knowledge I didn’t realize I could call the field label (if that’s it name) with the function. I’m learning, which is good.

    @david I had been using the function to cut down on repeat code with lots custom field types. I started using a plugin to handle custom fields to clean up the back end. Now the only field left is video. I could drop the function completely.

    Thanks you very much gentle men!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to get_post_meta and if else statement’ is closed to new replies.