Make WordPress Core

Ticket #32942: 32942.1.diff

File 32942.1.diff, 6.8 KB (added by chiragrathod103, 3 years ago)

I have divided post count in 2 column

  • src/wp-admin/includes/class-wp-terms-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php
    index 3c277d6a61..3606e74651 100644
    a b class WP_Terms_List_Table extends WP_List_Table { 
    195195                        'slug'        => __( 'Slug' ),
    196196                );
    197197
     198                // Check if current taxonomy assigned in multiple post type
     199                if ( 'attachment' != $this->screen->post_type ) {
     200                        $taxonomy_object = get_taxonomy( $this->screen->taxonomy );
     201                        if ($taxonomy_object) {
     202                                $assigned_post_types = $taxonomy_object->object_type;
     203
     204                                if (is_array($assigned_post_types) && count($assigned_post_types) > 1) {
     205                                        // If assigned multiple post type then only below column will add.
     206                                        $columns['otherposts'] = _x( 'Current Count', 'Number/count of items' );
     207                                }
     208                        }
     209                }
     210
    198211                if ( 'link_category' === $this->screen->taxonomy ) {
    199212                        $columns['links'] = __( 'Links' );
    200213                } else {
    class WP_Terms_List_Table extends WP_List_Table { 
    220233                        'name'        => array( 'name', false, _x( 'Name', 'term name' ), $name_orderby_text, 'asc' ),
    221234                        'description' => array( 'description', false, __( 'Description' ), __( 'Table ordered by Description.' ) ),
    222235                        'slug'        => array( 'slug', false, __( 'Slug' ), __( 'Table ordered by Slug.' ) ),
     236                        'otherposts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Current Posts Count.' ) ),
    223237                        'posts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ),
    224238                        'links'       => array( 'count', false, __( 'Links' ), __( 'Table ordered by Links.' ) ),
    225239                );
    class WP_Terms_List_Table extends WP_List_Table { 
    571585                return apply_filters( 'editable_slug', $tag->slug, $tag );
    572586        }
    573587
     588        /**
     589         * @param WP_Term $tag Term object.
     590         * @return string
     591         */
     592        public function column_otherposts( $tag ) {
     593                $count = number_format_i18n( $tag->count );
     594
     595                $tax = get_taxonomy( $this->screen->taxonomy );
     596
     597                $ptype_object = get_post_type_object( $this->screen->post_type );
     598                if ( ! $ptype_object->show_ui ) {
     599                        return $count;
     600                }
     601
     602                if ( $tax->query_var ) {
     603                        $args = array( $tax->query_var => $tag->slug );
     604                } else {
     605                        $args = array(
     606                                'taxonomy' => $tax->name,
     607                                'term'     => $tag->slug,
     608                        );
     609                }
     610
     611                if ( 'post' !== $this->screen->post_type ) {
     612                        $args['post_type'] = $this->screen->post_type;
     613                }
     614
     615                $query_args = array(
     616                        'post_type' => $this->screen->post_type,
     617                        'post_status' => 'publish',
     618                        'tax_query' => array(
     619                                array(
     620                                        'taxonomy' => $this->screen->taxonomy,
     621                                        'field' => 'id',
     622                                        'terms' => array( $tag->term_id ),
     623                                ),
     624                        ),
     625                );
     626                $the_query = new WP_Query( $query_args );
     627               
     628                if ( isset( $the_query->found_posts ) ) {
     629                       
     630                        return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$the_query->found_posts</a>";
     631                }
     632
     633                return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
     634        }
     635
    574636        /**
    575637         * @param WP_Term $tag Term object.
    576638         * @return string
    class WP_Terms_List_Table extends WP_List_Table { 
    688750                                'description' => true,
    689751                                'name'        => true,
    690752                                'slug'        => true,
     753                                'otherposts'  => true,
    691754                                'posts'       => true,
    692755                        );
    693756