Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/e731fff96745f0969ccb5cf60b2a4920 to your computer and use it in GitHub Desktop.
Save dwanjuki/e731fff96745f0969ccb5cf60b2a4920 to your computer and use it in GitHub Desktop.
Redirect visitors without membership access form the The Events Calendar archive page
<?php
/**
* Redirect visitors without membership access form the The Events Calendar archive page
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_tribe_events_archive_require_membership() {
if ( is_post_type_archive( 'tribe_events' ) && function_exists( 'pmpro_hasMembershipLevel' ) && ! pmpro_hasMembershipLevel( array( 1, 2, 3 ) ) ) {
$location = home_url( '/path-to-redirect/' );
$location = wp_sanitize_redirect( $location );
header( 'Location: '. $location, true, 302 );
}
}
add_action( 'template_redirect', 'my_tribe_events_archive_require_membership' );
@dwanjuki
Copy link
Author

dwanjuki commented Apr 4, 2025

Using header() as wp_redirect() isn't working with the tribe_events post type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment