WordPress.org

Support

Support » How-To and Troubleshooting » display text if post has certain term of custom tax.

display text if post has certain term of custom tax.

  • miketopher
    Participant

    @miketopher

    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

Viewing 1 replies (of 1 total)
  • 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; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘display text if post has certain term of custom tax.’ is closed to new replies.