Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created January 13, 2020 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/465949e4a2b18abcef2e08fa3acbaf40 to your computer and use it in GitHub Desktop.
Save andrewlimaza/465949e4a2b18abcef2e08fa3acbaf40 to your computer and use it in GitHub Desktop.
Show list of users that purchased a post
<?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