Hide Events from Non-Members

Home Forums Calendar Products Events Calendar PRO Hide Events from Non-Members

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #43060
    catrancher
    Participant

    I’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.

    #43063
    Barry
    Member

    Can you share your code?

    #43065
    catrancher
    Participant

    Sure 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.

    #43554
    catrancher
    Participant

    Any update Barry?

    Thanks,
    Tom G.

    #43580
    Barry
    Member

    Sorry 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.

    #43581
    catrancher
    Participant

    Thanks Barry. Ok. Let me see what I can work out with the tribe_get_events filter.

    Tom G.

    #978837
    Support Droid
    Keymaster

    This 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.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Hide Events from Non-Members’ is closed to new replies.