Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Filter by Rating
- add_action( 'restrict_manage_posts', 'bpl_admin_posts_filter_restrict_reviews_by_rating' );
- function bpl_admin_posts_filter_restrict_reviews_by_rating(){
- $type = 'customer_reviews';
- if (isset($_GET['post_type'])) { $type = $_GET['post_type']; }
- //only add filter to post type you want
- if ('customer_reviews' == $type){
- //change this to the list of values you want to show
- //in 'label' => 'value' format
- $r_values = array(
- '5 Star Reviews' => '5',
- '4 Star Reviews' => '4',
- '3 Star Reviews' => '3',
- '2 Star Reviews' => '2',
- '1 Star Reviews' => '1',
- );
- echo "<select name=\"bpl_rating_value\"><option value=\"\">Rating</option>";
- $current_v = isset($_GET['bpl_rating_value'])? $_GET['bpl_rating_value']:'';
- foreach ($r_values as $label => $value) {
- printf (
- '<option value="%s"%s>%s</option>',
- $value,
- $value == $current_v? ' selected="selected"':'',
- $label
- );
- }
- echo "</select>";
- }
- }
- add_filter( 'parse_query', 'bpl_posts_filter_reviews_by_rating' );
- function bpl_posts_filter_reviews_by_rating( $query ){
- global $pagenow;
- $type = 'customer_reviews';
- if (isset($_GET['post_type'])) { $type = $_GET['post_type']; }
- if ( 'customer_reviews' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['bpl_rating_value']) && $_GET['bpl_rating_value'] != '') {
- $query->query_vars['meta_key'] = 'cust_rating';
- $query->query_vars['meta_value'] = $_GET['bpl_rating_value'];
- }
- }
- // Filter by Technician
- add_action('restrict_manage_posts','restrict_bpl_reviews_by_tech');
- function restrict_bpl_reviews_by_tech() {
- global $wpdb;
- $type = 'customer_reviews';
- if (isset($_GET['post_type'])) { $type = $_GET['post_type']; }
- if ('customer_reviews' == $type){
- $techs = $wpdb->get_col("SELECT DISTINCT meta_value FROM ". $wpdb->postmeta ." WHERE meta_key = 'customer_tech' ORDER BY meta_value");
- echo "<select name=\"bpl_restrict_reviews_by_tech\" id=\"review_techs\"><option value=\"\">Technician</option>";
- foreach ($techs as $tech) :
- $the_value = unserialize( $tech );
- echo "<option value=\"",$the_value[0],"\">";
- if ( isset ($_GET['bpl_restrict_reviews_by_tech']) && !empty($_GET['bpl_restrict_reviews_by_tech']) ) { selected($_GET['bpl_restrict_reviews_by_tech'], $tech); }
- $tech = get_post($tech);
- echo get_the_title($the_value[0]);
- echo "</option>";
- endforeach;
- echo "</select>";
- }
- }
- add_filter( 'parse_query', 'bpl_posts_filter_reviews_by_tech' );
- function bpl_posts_filter_reviews_by_tech( $where ){
- global $pagenow;
- $type = 'customer_reviews';
- if (isset($_GET['post_type'])) { $type = $_GET['post_type']; }
- if ( 'customer_reviews' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['bpl_restrict_reviews_by_tech']) && $_GET['bpl_restrict_reviews_by_tech'] != '') {
- $where->query_vars['meta_key'] = 'customer_tech';
- $where->query_vars['meta_value'] = $_GET['bpl_restrict_reviews_by_tech'];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement