Last active
February 17, 2023 14:08
-
-
Save rocketgeek/28f7cb33347097a540bde9cd80df4499 to your computer and use it in GitHub Desktop.
Display a list of membership posts a user has access to
This file contains hidden or 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 // do not include this line. | |
/** | |
* Adds a custom shortcode to display membership restricted | |
* posts that a user has access to. | |
* | |
* shortcode: [show_my_posts] | |
*/ | |
add_shortcode( 'show_my_posts', 'my_show_my_posts' ); | |
function my_show_my_posts( $atts, $content, $tag ) { | |
// Go through each membership the user has. | |
foreach ( wpmem_get_user_memberships() as $key => $value ) { | |
// Get a list of content. | |
$ids = wpmem_get_membership_post_list( $key ); | |
$post_list = '<ul>'; | |
foreach ( $ids as $id ) { | |
$title = get_the_title( $id ); | |
$link = '<a href="' . get_permalink( $id ) . '">' . $title . '</a>'; | |
$post_list .= '<li>' . $link . '</li>'; | |
} | |
$post_list .= "</ul>"; | |
$title = "<h2>" . wpmem_get_membership_name( $key ) . "</h2>"; | |
$content .= $title . $post_list; | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment