How can I make this expression pull 2 custom fields?

efeezy

New member
Oct 5, 2007
5,250
136
0
50
I'd like to have this code below pull either the custom field "a2pImage" OR "thumbnail", but not both at the same time. . Is there a way to alter the code to make this happen? Right now it's only pulling a2pImage. Is there a way to set it up to look for either of those custom fields and pull the one that is available.

<a href="<?php the_permalink() ?>" rel="bookmark" title="Read the Full Review »"><img src="<?php $key="a2pImage"; echo get_post_meta($post->ID, $key, true); ?>" alt="thumbnail" class="thumbnail" /></a>
 


Ok. Right now, my homepage is showing thumbnails from posts. When Auction2Post creates new posts it also generates a bunch of custom fields automatically. One of those custom fields for the post is a2pImage, which it assigns the url of the image A2P uploads to my server. This is the custom field that is being displayed for the homepage thumbnails. That's all fine and dandy, however, I have a hundred older posts that use the custom field "thumbnail" and have an image URL attached.

I'm looking to have my homepage recognize both a2pImage & thumbnail as possible sources to pull the thumbnail from. None of the posts are going to have both of those custom fields, just one or the other. This is the part of the code that I'm hoping can be modified in some way to include the "thumbnail" custom field.

$key="a2pImage"; echo get_post_meta

I hope I've explained this better. Thanks.
 
Create a wrapper function that calls get_post_meta with "a2pImage" as the key; if null then call it with "thumbnail" as the key; returning whichever value is found.

Then call that wrapper function from your img src php snippet.
 
I'd like to have this code below pull either the custom field "a2pImage" OR "thumbnail", but not both at the same time. . Is there a way to alter the code to make this happen? Right now it's only pulling a2pImage. Is there a way to set it up to look for either of those custom fields and pull the one that is available.

<a href="<?php the_permalink() ?>" rel="bookmark" title="Read the Full Review »"><img src="<?php $key="a2pImage"; echo get_post_meta($post->ID, $key, true); ?>" alt="thumbnail" class="thumbnail" /></a>

Code:
<a href="<?php the_permalink() ?>" rel="bookmark" title="Read the Full Review »"><img src="<?php 

echo ( ($thumb = get_post_meta($post->ID, "a2pImage", true)) ) ? $thumb : get_post_meta($post->ID, "thumbnail", true);

?>" alt="thumbnail" class="thumbnail" /></a>
 
  • Like
Reactions: efeezy
Code:
<a href="<?php the_permalink() ?>" rel="bookmark" title="Read the Full Review »"><img src="<?php 

echo ( ($thumb = get_post_meta($post->ID, "a2pImage", true)) ) ? $thumb : get_post_meta($post->ID, "thumbnail", true);

?>" alt="thumbnail" class="thumbnail" /></a>

Gump...you're a goddamn genius.

Rep for you sir. Thanks.