• I have searched a lot of forums for this and a few people have had the same issue but no solutions so far.

    I have an events site and have added tags to some events named ‘non-spektrix’ these are local events not linked to a ticketing site so I want to hide the tickets box (#instancesBlock) when an event has been tagged ‘non-spektrix’. Is this possible?

    I basically want to add some code to say:

    If an event (post_type) has been tagged as ‘non-spektrix’
    use this style:
    #instancesBlock {display: none;}

    would this go in my functions.php file?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Fi Fi P

    (@fi-fi-p)

    I tried the code below, and nothing!

    <?php if($post->ID == “696”){

    <style> #instancesBlock {display: none;} </style>

    <?php } ?>

    Thread Starter Fi Fi P

    (@fi-fi-p)

    <?php if( get_field(‘non_spektrix’) ): ?>
    <style>.block-content #instancesBlock{display: none;} </style>
    <?php endif; ?>

    I believe it would need to go in the loop in your template file. I could be incorrect in thinking that however.

    So somewhere after:

    <?php while ( have_posts() ) : the_post(); ?>

    You could do something like:

    if( has_term( 'non-spektrix', 'taxonomy-name' ) ) {
        // do something
    }

    Replace taxonomy name with the name of the taxonomy that non-spektrix belongs to. Or if get_field in your second example is a true/false ACF field, that might work in the loop also.

    Thread Starter Fi Fi P

    (@fi-fi-p)

    Its the // do something bit I think I am getting wrong

    <?php
    if( has_term( ‘event’, ‘non-spektrix’ ) ) {
    <style>.block-content #instancesBlock{display: none;} </style>
    }
    <?php endif; ?>

    The above isn’t working still for an event tagged as ‘non-spektrix’
    I will want to do something similar with hiding a div when a certain page template is used but I am definately missing somehting here!

    Would you be able to show the code from the section you’re working with? I’m thinking you might not need to use styles. You could possibly just check to see if the post has the term, and if it does, don’t display the box markup, if it doesn’t, display the box markup.

    <?php
    if ( has_term( 'non-spektrix', 'event' ) ) {
         // do nothing
    } else {
         // ticket box markup
    }
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Targeting a taxonomy’ is closed to new replies.