Created
January 13, 2020 13:26
-
-
Save andrewlimaza/465949e4a2b18abcef2e08fa3acbaf40 to your computer and use it in GitHub Desktop.
Show list of users that purchased a post
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
<?php | |
/** | |
* Use shortcode [posts_users_example post_id='12'] | |
* Tweak code to your liking, this is a starter example. | |
* Add code via this method - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_shortcode_example( $atts ) { | |
if ( empty( $atts['post_id'] ) ) { | |
return 'no post ID supplied'; | |
} | |
$post_users = get_post_meta( $atts['post_id'], '_pmproap_users', true ); | |
// Loop through posts and get users belonging to that post. | |
if ( is_array( $post_users ) ) { | |
$list = '<ul>'; | |
foreach( $post_users as $key => $user_id ) { | |
$user = get_user_by( 'ID', $user_id ); | |
$list .= '<li>' . $user->user_login . '</li>'; | |
} | |
$list .= '</ul>'; | |
} | |
return $list; | |
} | |
add_shortcode( 'posts_users_example', 'my_shortcode_example' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment