Removing category from List Views BUT NOT from users My Events view

Home Forums Calendar Products Community Events Removing category from List Views BUT NOT from users My Events view

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1167048
    jussibr
    Participant

    HI there –

    I have been using the following code in my functions.php file to remove an event category from my main upcoming events view. The events are is still visible on the site when accessed directly by the category link. It works well except that it also seems to be removing these events from being listed on the ‘My Events’ page that a user sees when logged in. So users think the events have not been published. Is there a way to configure the code so that the events are still shown on the My Events page?

    Thanks!

    /*
     * The Events Calendar Remove Events from Month and List Views
     * add coding to theme's functions.php
     * @version 3.12
     * modify here with event category slugs: array( 'concert', 'convention' )
    */
    add_action( 'pre_get_posts', 'tribe_exclude_events_category_month_list' );
    function tribe_exclude_events_category_month_list( $query ) {
    
    	if ( isset( $query->query_vars['eventDisplay'] ) && ! is_singular( 'tribe_events' ) ) {
    
    		if ( $query->query_vars['eventDisplay'] == 'list' && ! is_tax( Tribe__Events__Main::TAXONOMY ) || $query->query_vars['eventDisplay'] == 'month' && $query->query_vars['post_type'] == Tribe__Events__Main::POSTTYPE && ! is_tax( Tribe__Events__Main::TAXONOMY ) && empty( $query->query_vars['suppress_filters'] ) ) {
    
    			$query->set( 'tax_query', array(
    
    				array(
    					'taxonomy' => Tribe__Events__Main::TAXONOMY,
    					'field'    => 'slug',
    					'terms'    => array( 'kids-camp-programs', 'kids-programs-and-workshops' ),
    					'operator' => 'NOT IN'
    				)
    			) );
    		}
    
    	}
    
    	return $query;
    }
    
    #1167174
    Andras
    Keymaster

    Hello jussibr,

    Thanks for using our plugins and for reaching out! I’ might be able to help you with this.

    You will need to add another conditional statement to check if it is the My Events page or not. The function for it is tribe_is_community_my_events_page(). This does as says, tells you whether you are looking at the My Events page (true) or not (false).

    I hope this helps. Let me know how it works out.

    Cheers,
    Andras

    #1168473
    jussibr
    Participant

    Hi Andras – thanks for this. I am going to see if I can make it work. I will let you know how it goes!

    #1168617
    Andras
    Keymaster

    Great, looking forward to see how it works out! 🙂

    Have a great start of the week!

    Andras

    #1169830
    jussibr
    Participant

    Hi Andras,

    Unfortunately writing this code appears to be above my skill level. Is there any way I can get more help with it?

    Justine

    #1170265
    Andras
    Keymaster

    Hey jussibr,

    No worries, let’s see how we can work this out.

    I tweak the code a tiny bit so that the modified query is NOT run when you are looking at the My Events page.

    Check if it helps.

    https://gist.github.com/andrasguseo/60a26cd98acd4d6b077d25207f19e734

     

    I didn’t understand correctly “still visible on the site when accessed directly by the category link”. Is that good like that or you want to hide them there as well?

    Cheers,
    Andras

    #1170943
    jussibr
    Participant

    Hi Andras,

    The new code works perfectly! Thank you so much for your help!

    Justine

    #1171714
    Andras
    Keymaster

    Hey Justine,

    I’m super happy it helped! 🙂

    I am going to go ahead and close this ticket, but if you need help on this or something else, don’t hesitate to open a new topic. We’ll be here to help.

    Cheers,
    Andras

    PS: We’d be grateful if you would give us feedback on your satisfaction with support. Just click on one of the classy looking emojis below. 🙂 If you can spare a few words, that’s even better. Thanks!

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Removing category from List Views BUT NOT from users My Events view’ is closed to new replies.