• racemanyaya

    (@racemanyaya)


    Hi, I try to had a text “promotion” on a product image. I have create a custom field “promo” in my post-type. When the get_post_meta find the promo custom field I want ti display a small div that will show text over my prodcut image.

    Here the code I have but it not working, I’m learning php.

    <div class="packageImage">
    <?php $promo = get_post_meta(get_the_ID(), 'promo', true); ?>
    <?php if ($promo): ?>
    <div class="packagePromoItem">Promotion</div>
    <?php endif; ?>
    <a alt="" href="<?php echo get_post_meta(get_the_ID(), 'wpcf-fichier-pdf', true); ?>" target="_blank"><img class="packageImage2" alt="" title="" src="<?php echo get_post_meta(get_the_ID(), 'wpcf-featured-images', true); ?>"></a>
    </div>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    get_post_meta() always returns something, even if an empty string or array, which all resolve to true, so you’ll need to equate $promo to something for the conditional to work properly.

    As it stands, you should at least be getting the “Promotion” text, though it may not be visible. Check the page’s source HTML to confirm. To get it to show in the right place is simply a matter of the correct CSS.

Viewing 1 replies (of 1 total)
  • The topic ‘Get_post_meta to had image text’ is closed to new replies.