Created
April 13, 2017 02:56
-
-
Save greathmaster/eb30b7b42823cbee439acd14539e9316 to your computer and use it in GitHub Desktop.
Shortcode to display pages a current member has access to...see comments and notes for details.
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
/* | |
Shortcode to display pages a current member has access to. Only shows those pages with explicit membership settings. ie those set with the | |
"Require Membership" box on pages, CPTs (if the PMPro CPTs plugin is used), and posts. It does not show those posts restricted by categories. | |
*/ | |
function member_content_list($atts) | |
{ | |
$args = shortcode_atts(array('post_type' => 'page'), $atts); | |
$post_type = $args['post_type']; | |
global $wpdb; | |
$level = pmpro_getMembershipLevelForUser(); | |
$sql = "SELECT * FROM $wpdb->pmpro_memberships_pages LEFT JOIN $wpdb->posts ON $wpdb->pmpro_memberships_pages.page_id = $wpdb->posts.ID WHERE post_type = '$post_type' AND $wpdb->pmpro_memberships_pages.membership_id = $level->id"; | |
$results = $wpdb->get_results($sql, OBJECT); | |
ob_start(); | |
foreach ($results as $result) | |
{?> | |
<li><a href="<?php echo esc_url( get_permalink($result->page_id) ); ?>"><?php esc_html_e($result->post_title); ?></a></li><?php | |
} | |
$list = ob_get_contents(); | |
ob_end_clean(); | |
return $list; | |
} | |
add_shortcode('member_content_list' , 'member_content_list'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment