1

On a bog standard single.php file how can I echo the following if the post category = "Events" or category ID '4'. The code I'm looking to echo is :

        <div class="event-post-icons">
            <ul>
                <li class="single-post-date"><?php the_field('event_date'); ?></li>
                <li class="single-post-time"><?php the_field('event_time'); ?></li>
                <li class="single-post-price"><?php the_field('booking_fee'); ?></li>
                <li class="single-post-palce"><?php the_field('event_location'); ?></li>
            </ul>
        </div><!-- /event-post-icons -->

Thanks

2

Use the in_category() function, like this:

<?php if ( in_category( 4 ) ) : ?>
    <div class="event-post-icons">
        <ul>
            <li class="single-post-date"><?php the_field('event_date'); ?></li>
            <li class="single-post-time"><?php the_field('event_time'); ?></li>
            <li class="single-post-price"><?php the_field('booking_fee'); ?></li>
            <li class="single-post-palce"><?php the_field('event_location'); ?></li>
        </ul>
    </div><!-- /event-post-icons -->
<?php endif; ?>

If you are using this to test a post outside of The Loop, you would need to add the post id:

<?php if ( in_category( 4, $post_id ) ) : ?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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