Plugin Directory

Changeset 1345521


Ignore:
Timestamp:
02/08/2016 03:57:59 AM (10 years ago)
Author:
rohanmehta19
Message:

fixed error for post types where custom cols were not declared

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wpi-custom-admin-columns-for-sorting-and-filtering/trunk/wpi_custom_filter.php

    r1345514 r1345521  
    44    var $field_headings;
    55    var $unset_cols;
     6    var $post_type_arr;
    67   
    78    public function __construct() {
     
    1011       
    1112        $wpi_cf_fields=esc_attr($wpi_admin_custom_filter_options[$this->post_type]);
     13        $this->wpi_cf_fields_comma_separated=$wpi_cf_fields;
    1214        $wpi_cf_labels=esc_attr($wpi_admin_custom_filter_options[$this->post_type.'_labels']);
    1315       
    14         if($wpi_cf_fields != NULL) $post_types_arr[]=$post_type;
    15         $this->post_type_arr=$post_types_arr;
    16        
     16   
    1717        if($wpi_cf_labels==NULL) $wpi_cf_labels=$wpi_cf_fields;
    1818        $this->wpi_cf_fields = explode(',',$wpi_cf_fields);
    1919        $this->wpi_cf_labels = explode(',',$wpi_cf_labels);
    20        
     20        //echo $this->wpi_cf_fields;
    2121        add_filter('manage_edit-'.$this->post_type.'_columns', array($this, 'wpi_table_head'));
    2222        add_action('manage_'.$this->post_type.'_posts_custom_column', array($this, 'wpi_table_content'), 10, 2);
     
    2929        $this->fields=$this->wpi_cf_fields;
    3030        $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');
    3232    }
    3333
     
    3939        }
    4040       
    41         foreach($this->unset_cols as $ucols){
    42             unset($defaults[$ucols]);
    43         }
     41       // foreach($this->unset_cols as $ucols){
     42        //    unset($defaults[$ucols]);
     43       // }
    4444
    4545        return $defaults;
     
    4747
    4848    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            }
    5254        }
    5355    }
    5456
    5557    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            }
    5862        }
    5963        return $columns;
     
    6266
    6367    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 ) {
    6569        foreach($this->fields as $field){
    6670            if (isset($vars['orderby']) && $field == $vars['orderby']) {
     
    8084
    8185        $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 ) {
    8387            if ($_GET['filter_action'] == 'Filter') {
    8488                global $wpdb;
     
    120124        global $wpdb;
    121125        global $pagenow;
    122         if (is_admin() && $pagenow == 'edit.php') {
     126        if (is_admin() && $pagenow == 'edit.php' && $this->wpi_cf_fields_comma_separated != NULL ) {
    123127            foreach($this->fields as $field){
    124128               $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                 <?php
    133             }
    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>';
    135139            }
    136140
Note: See TracChangeset for help on using the changeset viewer.