Support

Home Forums Event Espresso Premium Exclude events of x category from appearing in People posts

Exclude events of x category from appearing in People posts

Posted: July 8, 2020 at 3:33 pm


Praxis

July 8, 2020 at 3:33 pm

Hi folks,
I’m trying to hide all events with the event category “private” from appearing anywhere on the site. I’ve gotten everything except for the People template covered.
Here’s my version of the EE People template:

global $post;
$events = EEH_People_View::get_events_for_person();
?>
<div class="eea-people-addon-person-events-container">
	<?php if ( $events ) : ?>
	<h3><?php _e('Upcoming Workshops & Courses:', 'event_espresso'); ?></h3>
	<?php foreach ( $events as $type => $event ) :  ?>
		<div class="eea-people-addon-people-type-container">
			<h4 class="eea-people-addon-people-type-label"><?php echo $type; ?></h4>
			<ul class="eea-people-addon-event-list-ul">
				<?php foreach ( $event as $evt ): 
				 
				 if ( ($evt->is_active() || $evt->is_upcoming()) && ! $evt->is_sold_out(TRUE)):
				?>
				
					
  • ID() ); ?>" title="<?php printf( __('Learn more about %s', 'event_espresso' ), $evt->name() ); ?>"><span class="eea-people-addon-event-name"><?php echo $evt->name(); ?></span>
  • <?php endif; ?> <?php endforeach; ?> </div> <?php endforeach; ?> <?php endif; ?> </div>

    I have tried to edit the IF statement to include

    if ( ($evt->is_active() || $evt->is_upcoming()) && ! $evt->is_sold_out(TRUE)) {
    	if !(has_term('private', 'espresso_event_categories'))
    }:
    

    or

    if ( ($evt->is_active() || $evt->is_upcoming()) && ! ($evt->is_sold_out(TRUE) || has_term('private', 'espresso_event_categories') ) ):
    

    But neither make a difference in the outcome. I obviously have some incorrect syntax here, but I can’t seem to figure out the right syntax.
    Can you help?


    Tony

    • Support Staff

    July 9, 2020 at 4:15 am

    Hi there,

    has_term() works on the global $post object if you don’t pass in an ID/Post to the function, the $event variable in that foreach loop is not the global $post object at that point so it won’t work as-is.

    You need to pass the event’s ID to has_term, like so:

    has_term('private', 'espresso_event_categories', $event->ID())


    Praxis

    July 9, 2020 at 10:59 am

    That makes perfect sense. Thanks so much, Tony! It’s working now.

    The support post ‘Exclude events of x category from appearing in People posts’ is closed to new replies.

    Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

    Event Espresso