Skip to content

Instantly share code, notes, and snippets.

@eighty20results
Created January 12, 2016 20:33
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 eighty20results/8a2f544fc2cdb48efd24 to your computer and use it in GitHub Desktop.
Save eighty20results/8a2f544fc2cdb48efd24 to your computer and use it in GitHub Desktop.
/** 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