Created
June 19, 2018 18:28
-
-
Save kimcoleman/db99f11eb2709d10831ce54abd11a796 to your computer and use it in GitHub Desktop.
Display Advanced Custom Fields based on the post's membership requirements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/