Home › Forums › Calendar Products › Events Calendar PRO › Hide Events from Non-Members
- This topic has 6 replies, 3 voices, and was last updated 10 years, 10 months ago by
Support Droid.
-
AuthorPosts
-
March 18, 2013 at 8:07 am #43060
catrancher
ParticipantI’m using the Members plugin from Justin Tadlock on my homeowners association site and have established a capability that restricts post visibility to homeowners association members only. I’ve done this by adding a “pre_get_posts” filter on the the main query that filters on user meta information by querying for the members capability. So far so good. All posts that are marked for homeowners only are blocked.
Now within Event Calendar PRO, I’m able to specify that certain events are for homeowners only and in the “Event List” view, they are indeed blocked and do not show up. However, in the “Calendar (grid)” view, they’re still visible.
I’ve verified that my filter is being executed for both the Event List view as well as the Calendar view. Any ideas why these events would be hidden in the Event List view (as they should be) but show up in the Calendar view?Thanks!
Tom G.March 18, 2013 at 8:44 am #43063Barry
MemberCan you share your code?
March 18, 2013 at 8:54 am #43065catrancher
ParticipantSure Barry. Thanks. Here’s the filter I’m using. Hope it’s OK like this:
function tg_pre_get_posts_query( $query ) {
if (current_user_can( ‘view_hoa_content’ ) ) {
return;
} elseif ( $query->is_main_query() && !is_admin() ) {
$meta_query = array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘_members_access_role’,
‘value’ => ”,
‘compare’ => ‘NOT EXISTS’
),
array(
‘key’ => ‘_members_access_role’,
‘value’ => ‘homeowner’,
‘compare’ => ‘!=’
)
);
$query->set( ‘meta_query’, $meta_query );
}
return;
}add_action( ‘pre_get_posts’, ‘tg_pre_get_posts_query’ );
Let me know if you need more information! And thanks,
Tom G.
March 21, 2013 at 4:45 am #43554catrancher
ParticipantAny update Barry?
Thanks,
Tom G.March 21, 2013 at 7:56 am #43580Barry
MemberSorry for the delay Tom, but yes: the code will not run because pre_get_posts doesn’t fire in that scenario so, basically, you’d have to find another way of doing this – such as using the tribe_get_events filter.
I’ve verified that my filter is being executed for both the Event List view as well as the Calendar view.
To clarify, pre_get_posts will typically happen one or more times during the request – but not in relation to the events being fetched for the calendar grid.
March 21, 2013 at 7:57 am #43581catrancher
ParticipantThanks Barry. Ok. Let me see what I can work out with the tribe_get_events filter.
Tom G.
July 7, 2015 at 6:26 am #978837Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘Hide Events from Non-Members’ is closed to new replies.
