Changeset 1345521
- Timestamp:
- 02/08/2016 03:57:59 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wpi-custom-admin-columns-for-sorting-and-filtering/trunk/wpi_custom_filter.php
r1345514 r1345521 4 4 var $field_headings; 5 5 var $unset_cols; 6 var $post_type_arr; 6 7 7 8 public function __construct() { … … 10 11 11 12 $wpi_cf_fields=esc_attr($wpi_admin_custom_filter_options[$this->post_type]); 13 $this->wpi_cf_fields_comma_separated=$wpi_cf_fields; 12 14 $wpi_cf_labels=esc_attr($wpi_admin_custom_filter_options[$this->post_type.'_labels']); 13 15 14 if($wpi_cf_fields != NULL) $post_types_arr[]=$post_type; 15 $this->post_type_arr=$post_types_arr; 16 16 17 17 if($wpi_cf_labels==NULL) $wpi_cf_labels=$wpi_cf_fields; 18 18 $this->wpi_cf_fields = explode(',',$wpi_cf_fields); 19 19 $this->wpi_cf_labels = explode(',',$wpi_cf_labels); 20 20 //echo $this->wpi_cf_fields; 21 21 add_filter('manage_edit-'.$this->post_type.'_columns', array($this, 'wpi_table_head')); 22 22 add_action('manage_'.$this->post_type.'_posts_custom_column', array($this, 'wpi_table_content'), 10, 2); … … 29 29 $this->fields=$this->wpi_cf_fields; 30 30 $this->field_headings=$this->wpi_cf_labels; 31 $this->unset_cols=array('comments','taxonomy-term_category','tags','author');31 //$this->unset_cols=array('comments','taxonomy-term_category','tags','author'); 32 32 } 33 33 … … 39 39 } 40 40 41 foreach($this->unset_cols as $ucols){42 unset($defaults[$ucols]);43 }41 // foreach($this->unset_cols as $ucols){ 42 // unset($defaults[$ucols]); 43 // } 44 44 45 45 return $defaults; … … 47 47 48 48 function wpi_table_content($column, $post_id) { 49 foreach($this->fields as $field){ 50 if($column == $field) 51 echo get_post_meta($post_id, $field, true); 49 if ( $this->wpi_cf_fields_comma_separated != NULL ) { 50 foreach($this->fields as $field){ 51 if($column == $field) 52 echo get_post_meta($post_id, $field, true); 53 } 52 54 } 53 55 } 54 56 55 57 function wpi_table_sorting($columns) { 56 foreach($this->fields as $field){ 57 $columns[$field] = $field; 58 if (is_admin() && $pagenow == 'edit.php' && $this->wpi_cf_fields_comma_separated != NULL ) { 59 foreach($this->fields as $field){ 60 $columns[$field] = $field; 61 } 58 62 } 59 63 return $columns; … … 62 66 63 67 function wpi_column_orderby($vars) { 64 if (is_admin() && $pagenow == 'edit.php' ) {68 if (is_admin() && $pagenow == 'edit.php' && $this->wpi_cf_fields_comma_separated != NULL ) { 65 69 foreach($this->fields as $field){ 66 70 if (isset($vars['orderby']) && $field == $vars['orderby']) { … … 80 84 81 85 $qv = &$query->query_vars; 82 if (is_admin() && $pagenow == 'edit.php' ) {86 if (is_admin() && $pagenow == 'edit.php' && $this->wpi_cf_fields_comma_separated != NULL ) { 83 87 if ($_GET['filter_action'] == 'Filter') { 84 88 global $wpdb; … … 120 124 global $wpdb; 121 125 global $pagenow; 122 if (is_admin() && $pagenow == 'edit.php' ) {126 if (is_admin() && $pagenow == 'edit.php' && $this->wpi_cf_fields_comma_separated != NULL ) { 123 127 foreach($this->fields as $field){ 124 128 $result = $wpdb->get_results("SELECT DISTINCT meta_value FROM ".$wpdb->prefix."postmeta WHERE meta_key='".$field."'"); 125 echo '<select name="'.$field.'">';126 echo '<option value="">ALL</option>';127 foreach ($result as $print) {128 ?>129 <option value="<?php echo $print->meta_value; ?>" <?php if ($_GET[$field] == $print->meta_value) {130 echo 'selected="selected"';131 } ?>><?php echo $print->meta_value; ?></option>132 <?php133 }134 echo '</select>';129 echo '<select name="'.$field.'">'; 130 echo '<option value="">ALL</option>'; 131 foreach ($result as $print) { 132 ?> 133 <option value="<?php echo $print->meta_value; ?>" <?php if ($_GET[$field] == $print->meta_value) { 134 echo 'selected="selected"'; 135 } ?>><?php echo $print->meta_value; ?></option> 136 <?php 137 } 138 echo '</select>'; 135 139 } 136 140
Note: See TracChangeset
for help on using the changeset viewer.