Frontend and backend calendar? (PART 2 .. :-) )

Home Forums Welcome! Pre-Sales Questions Frontend and backend calendar? (PART 2 .. :-) )

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #964880
    Kalle Pedersen
    Guest

    Hi again,

    I posted a question on May 15. Geoff answered very nicely, but I didn’t quite find, what I was searching for.

    (https://theeventscalendar.com/support/forums/topic/frontend-and-backend-calendar/)

    Hence my follow-up:

    Hiding certain categories in the calendar is not an option as it will then hide this category for everyone.

    What I am searching for is the ability to display events / categories based on user roles.

    Is it perhaps possible (by shortcode or by modifying php) to display one calendar with ALL events (for the backend community users) and then to display a SECOND calendar that does not show draft events that have not yet been approved by an admin?

    Again: thanks a lot for the support and I hope your nice plugin can do, what I am searching for (one way or another 🙂 )

    Kind regards…

    #965012
    Kalle Pedersen
    Guest

    Hi again,

    I’m no pro, but I managed to “get it done” with inspiration from your previous reply + a little help from google.

    If anyone else needs it, this is what I added to my child theme’s “functions.php:

    // Removes categories “test1” and “test2” for users not logged in
    add_action( ‘pre_get_posts’, ‘exclude_events_category’ );

    function exclude_events_category( $query ) {

    get_currentuserinfo() ;
      global $user_level;
     
    
    	if ($user_level == 0) {
    	 
    		$query->set( 'tax_query', array(
    
    			array(
    				'taxonomy' => TribeEvents::TAXONOMY,
    				'field' => 'slug',
    				'terms' => array('test1', 'test2'),
    				'operator' => 'NOT IN'
    			)
    			)
    		);
    	}
    	return $query;
    	} 

    This hides chosen categories for users not logged in and by creating a category called e.g. “maybe”, the community members can add to a hidden category and then change to a visible category, when they want the event to be visible to all…

    #965089
    Brian
    Keymaster

    Great thanks for sharing this coding!

    You could also look to use is_user_logged_in() to tell if a person is logged in our not:

    https://codex.wordpress.org/Function_Reference/is_user_logged_in

    Cheers

    #974161
    Brian
    Keymaster

    Since I haven’t heard back from you here, I’m going to go ahead and close out this thread. Feel free to start a new thread if you have further issues. Thanks! 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Frontend and backend calendar? (PART 2 .. :-) )’ is closed to new replies.