echo get_post_meta breaking else { echo ” “;}
-
Okay, I’m not a php guru by any stretch of the imagination. However, I’ve hacked out a few things but can’t get this last bit to work. Here’s the background:
I’m a book blogger, so I enter a custom ISBN field (like a SKU) for each of my book review posts. At the bottom of each post I’ve used the custom ISBN field and the echo get_post_meta to create dynamic URLs to retailers for that specific ISBN. This part works like a charm.
But I want posts that don’t have an ISBN (non-book review posts) to NOT have this line of retailer links.
My logic – if $ISBN is null then do nothing, else use the retailer links.
So here’s what I have:
<?php $ISBN=get_post_meta($post->ID, ‘ISBN’, $single = true);
if ($ISBN = null) {
echo “”;
} else {echo “[retailer links]”;
}
?>Here is the retailer link code which works perfectly fine on it’s own.
Buy at:
<a href="https://www.dpbolvw.net/click-2492922-7134924?url=https://www.abebooks.com/servlet/SearchResults?isbn=<?php echo get_post_meta($post->ID, 'ISBN', $single = true); ?>">Abebooks</a>, <a href="https://click.linksynergy.com/fs-bin/stat?id=mpEZ5C07uXI&offerid=99238&type=3&subid=0&tmpid=939&RD_PARM1=https://www.alibris.com/search/search.cfm?qisbn=<?php echo get_post_meta($post->ID, 'ISBN', $single = true); ?>">Alibris</a>, <a href="https://www.amazon.com/exec/obidos/redirect?tag=usedbooksblog-20&path=tg/stores/offering/list/-/<?php echo get_post_meta($post->ID, 'ISBN', $single = true); ?>/used">Amazon</a>, <a href="https://search.barnesandnoble.com/used/productMatches.asp?PRC=&x=29&PEAN=<?php echo get_post_meta($post->ID, 'ISBN', $single = true); ?>&lkid=J16280994&pubid=K128472&byo=1">Barnes & Noble</a>, <a href="https://www.jdoqocy.com/click-2492922-10470209?url=https://www.biblio.com/isbn/<?php echo get_post_meta($post->ID, 'ISBN', $single = true); ?>.html">Biblio</a>
I figured I could just move this into the ” ” of the else and be done with it. But that returns a white page of nothing.
Why won’t the retailer links code work in my else statement? Help!
See code here: https://usedbooksblog.com/blog/the-partly-cloudy-patriot-by-sarah-vowell/
- The topic ‘echo get_post_meta breaking else { echo ” “;}’ is closed to new replies.