Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/** Accepts a level ID and returns all categories protected by that level(id) **/
function pmpro_getCategoriesForLevel($level_id)
{
global $wpdb;
$sql = "SELECT category_id FROM {$wpdb->pmpro_memberships_categories} WHERE membership_id = %d";
$sql = $wpdb->prepare($sql, $level_id);
return $wpdb->get_results($sql);
}
/** Accepts one (string = the slug value for the category) as the argument & returns list of membership levels for that category **/
function pmpro_getLevelsForCategory($category_slug)
{
global $wpdb;
// Get all categories in the s
$categories = get_categories();
$to_find = array();
// Make even a single slug into an array for processing purposes.
foreach($categories as $c) {
if ($category_slug == $c->slug ) {
$to_find = $c->cat_ID;
break;
}
}
$sql = "SELECT membership_id AS level_id FROM {$wpdb->pmpro_memberships_categories} WHERE category_id = %d";
// Return the list of IDs for the category
return $wpdb->get_results( $wpdb->prepare( $sql, $to_find ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.