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