post_status == 'private'); } // Whether the current posts is of the given level function is_post_level($level = 0) { global $postlevel_key; $val = get_post_custom_values($postlevel_key); if (!empty($val)) return ($val == $level); else return ($level == 0); } } else { // Not logged in, use define fast functions that don't use the DB function is_private() { return false; } function is_post_level($level = 0) { return ($level == 0); } } } } // Left join with the custom fields table so we can filter // based on level in the where clause function postlevel_posts_join($join) { global $wpdb; return " LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id " . $join; } // Change where clause to accept published posts and private posts // with a post level less than or equal to the user's level function postlevel_posts_where($where) { global $user_level, $postlevel_key, $wpdb; return str_replace('post_status = "publish"', '(post_status = "publish" OR (post_status = "private" ' . "AND ({$wpdb->postmeta}.meta_key = '$postlevel_key' " . "AND {$wpdb->postmeta}.meta_value <= $user_level )))", $where); } ?>