Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/db99f11eb2709d10831ce54abd11a796 to your computer and use it in GitHub Desktop.
Save kimcoleman/db99f11eb2709d10831ce54abd11a796 to your computer and use it in GitHub Desktop.
Display Advanced Custom Fields based on the post's membership requirements.
$post = get_queried_object();
if ( function_exists( 'pmpro_has_membership_access' ) ) {
// Check if the user has access to the post.
$hasaccess = pmpro_has_membership_access( $post->ID );
// Display Advanced Custom Fields if the user has access to the post.
if( ! empty( $hasaccess ) && function_exists( 'get_field' ) ) {
if ( get_field( 'test_field_1' ) ) {
the_field( 'test_field_1' );
}
if ( get_field( 'test_field_2' ) ) {
the_field( 'test_field_2' );
}
}
}
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Restrict the display of Advanced Custom Fields (ACF) fields by Membership Level" at Paid Memberships Pro here: https://www.paidmembershipspro.com/restrict-the-display-of-advanced-custom-fields-acf-fields-by-membership-level/

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