• I have imported a bunch of old posts into wordpress, and now their post images are not set as featured images, but as custom fields. So, what I’m looking for is a php code that can do this:

    1.) show the featured image,
    2.) however, if no featured image is set, show custom field called “post-image”
    3.) If no featured image or custom field is set, show a specific jpg image inside my wordpress folder (which will just show “no image available”.

    Can this be done?

    Thanks!

Viewing 1 replies (of 1 total)
  • sure, it can be done. Something like this:

    <?php
    //This must be in one loop
    
    if(has_post_thumbnail()) {
    	the_post_thumbnail();
    } else {
    if( trim(get_post_meta($post_id, $key, $single)<>''){echo <img src="'.trim(get_post_meta($post_id, $key, $single).'" />}
    else {echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';}	
    
    }}
    ?>

    [Code moderated: please ensure that your code is enclosed in backticks (`) or use the code button.]

Viewing 1 replies (of 1 total)
  • The topic ‘show custom field if no featured image is set?’ is closed to new replies.