0

I have an archive page that is listing a custom taxonomy. Under each listing, there are some buttons that were hardcoded into the template page that have call to actions associated with them. One of them I need removed or not to display, based on a specific custom taxonomy term. My thought was to hide it using CSS based on that fact. This is the code I used but it is not working.

<?php
$supplier_list = wp_get_post_terms($post->ID, 'supplier', array("fields" =>"names"));
//Starting if condition
if (in_array("tax1",$supplier_list)==0) {
?>
<p class="hide"></p>

<?php
} //End of IF condition
?>
<a href="<?php echo get_post_meta($post->ID, 'ecpt_tds', true); ?>">Download Button</a>

I need to hide the "Download Button" when the term for the listing is "tax1" which is in the taxonomy "supplier". I think it may be an if/else statement that needs to be here and I am not sure the condition is correct because it is showing the <p class="hide"> on all the listings, not just those in the tax1. Any help is appreciated.

1 Answer 1

0

I think you could use the has_term conditional here, like so:

<?php if( !has_term( 'tax1', 'supplier' ) ) { ?>
    <a href="<?php echo get_post_meta($post->ID, 'ecpt_tds', true); ?>">Download Button</a>
<?php } ?>
2
  • I need to hide the button if it has the tax1 term. Thanks for your suggestion but it didn't seem to do anything. Any other thoughts? Nov 10, 2016 at 21:28
  • Hmm, it works for me. This code basically says, "if this post does not have the term tax1 from the supplier taxonomy, display the following button". In other words, only output the button for posts that aren't tagged tax1. Did you place this within the Loop when testing?
    – Michelle
    Nov 10, 2016 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.