Support » Plugin: IssueM » Add Issue Number to Article List

Viewing 1 replies (of 1 total)
  • In case someone else needs this I found a solution:

    function mbe_change_table_column_titles($columns){
    	unset($columns['comments']);
        unset($columns['date']);// temporarily remove, to have custom column before date column
        $columns['issuem_issue_issue'] = 'Issue';
        $columns['date'] = 'Date';// readd the date column
        return $columns;
    }
    add_filter('manage_article_posts_columns', 'mbe_change_table_column_titles');
    
    function mbe_change_column_rows($column_name, $post_id){
        if($column_name == 'issuem_issue_issue'){
            echo get_the_term_list($post_id, 'issuem_issue', '', ', ', '').PHP_EOL;
        }
    }
    add_action('manage_article_posts_custom_column', 'mbe_change_column_rows', 10, 2);
    
    function mbe_change_sortable_columns($columns){
        $columns['issuem_issue_issue'] = 'issuem_issue_issue';
        return $columns;
    }
    add_filter('manage_edit-article_sortable_columns', 'mbe_change_sortable_columns');
    
    function mbe_sort_custom_column($clauses, $wp_query){
        global $wpdb;
        if(isset($wp_query->query['orderby']) && $wp_query->query['orderby'] == 'issue'){
            $clauses['join'] .= <<<SQL
    LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
    LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
    LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
    SQL;
            $clauses['where'] .= "AND (taxonomy = 'issuem_issue' OR taxonomy IS NULL)";
            $clauses['groupby'] = "object_id";
            $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC)";
            if(strtoupper($wp_query->get('order')) == 'ASC'){
                $clauses['orderby'] .= 'ASC';
            } else{
                $clauses['orderby'] .= 'DESC';
            }
        }
        return $clauses;
    }
    add_filter('posts_clauses', 'mbe_sort_custom_column', 10, 2);
    
    function mbe_print_admin_styles(){
        global $pagenow;
        if($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'article'){
            echo '
            <style type="text/css">
                .column-issuem_issue_issue{
                    width: 10%;
                }
            </style>
            '.PHP_EOL;
        }
    }
    add_action('admin_print_styles', 'mbe_print_admin_styles');

    Thanks to this: WordPress Stackexchange

Viewing 1 replies (of 1 total)
  • The topic ‘Add Issue Number to Article List’ is closed to new replies.