WordPress.org

Ready to get started?Download WordPress

Forums

display text if post has certain term of custom tax. (2 posts)

  1. miketopher
    Member
    Posted 1 year ago #

    I've looked all over and I cannot find something that is not all garbled up with other code which I cant figure how to clean for my use..

    I have what i feel is fairly simple, just not for me :-p

    ill be adding this code with a hook to display only on a post, or a product page from woocommerce...

    I have a custom taxonomy called Brand, under this are a handful of terms Nike, Apple, IBM, etc..

    how do i do this..
    if brand = Nike then display this picture..

    with some code before, it would detect if Nike existed on ANY post... then display it there.. which simply meant it displayed it everywhere.. which was way off..

    can anyone help?

    Thanks

  2. SiteGround
    Member
    Posted 1 year ago #

    Hello,

    You can add a check into your template file (single.php for a single post). You can use this code, for example to check if the brand field has Adidas entered into it and if so the text will be displayed:

    <?php if (get_post_meta($post->ID, 'brand', 'true') == 'Adidas'): ?>Place your image in plain HTML here :)<?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic