Home › Forums › Calendar Products › Events Calendar PRO › Passed events appearing as "Upcoming" — but only for non-admins
- This topic has 8 replies, 4 voices, and was last updated 9 years, 2 months ago by
Sean Sullivan.
-
AuthorPosts
-
January 15, 2017 at 10:08 am #1218784
Sean Sullivan
ParticipantHello,
Previous events are showing as “upcoming” on our website — but only some events, and only for some users.
The calendar events are only available to registered members of the site.
We’re using the [tribe_events_list] shortcode to display upcoming events on our home page, and users can also access the events on the /events page.
When logged in as an admin, everything works great. No problems.
But ‘subscriber’ level users are seeing old events listed as upcoming in both the widget *and* the /events page.
I can’t find any pattern in the old events that are appearing. :/
January 15, 2017 at 10:10 am #1218789Sean Sullivan
ParticipantThis reply is private.
January 15, 2017 at 10:11 am #1218792Sean Sullivan
ParticipantThis reply is private.
January 15, 2017 at 10:41 am #1218798Sean Sullivan
ParticipantThis reply is private.
January 15, 2017 at 11:09 am #1218802Sean Sullivan
ParticipantLooks like I’ve found the issue. Removing this code from my functions.php file did the trick:
add_action( 'pre_get_posts', 'my_pre_get_posts' ); function my_pre_get_posts( $query ) { // Bail if current user can restrict content or edit other users' posts. if ( current_user_can( 'restrict_content' ) || current_user_can( 'edit_others_posts' ) ) return; if ( is_user_logged_in() ) { $user = new WP_User( get_current_user_id() ); $meta_query = array( 'relation' => 'OR', array( 'key' => '_members_access_role', 'compare' => 'NOT EXISTS', ), array( 'key' => '_members_access_role', 'value' => $user->roles[0], 'compare' => '=' ) ); } else { $meta_query = array( array( 'key' => '_members_access_role', 'compare' => 'NOT EXISTS' ) ); } $query->set( 'meta_query', $meta_query ); }Any idea why the conflict is there?
January 15, 2017 at 11:16 am #1218804Sean Sullivan
Participant(Because I need that code to prevent non-registered users from viewing much of the members-only content).
January 16, 2017 at 3:14 pm #1219281Brook
ParticipantHowdy Sean,
Thank you for so thoroughly detailing the issue, and sharing your code. That helps cut right to the problem. I would love to help you from here.
Looking at your code, I am guessing the issue is that you are setting the meta_query variable, rather than updating it. This would override the current meta_query with your new details, removing anything other code has set.
What if, at the start of your code you ran:
$meta_query = $query->get( 'meta_query' );
And then inside of your if ( is_user_logged_in() ) {} else {} condition you appended the details to the existing query, as new array keys, rather than overriding it. Keep in mind you will need to wrap your relation query inside an array of its own, that way it does not set the entire query to an OR relation.
This might prove helpful:
https://codex.wordpress.org/Class_Reference/WP_Meta_Query
Does that all make sense? Will that work for you? Please let me know.
Cheers!
– Brook
February 7, 2017 at 8:35 am #1230664Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Passed events appearing as "Upcoming" — but only for non-admins’ is closed to new replies.
