1

I have added custom column to all posts page by this code:

// ADD NEW COLUMN
function len_columns_head($defaults) {
    $defaults['post_len'] = 'Symbols';
    return $defaults;
}
 
// SHOW POST LENGTH
function len_columns_content($column_name, $post_ID) {
    if ($column_name == 'post_len') {
        $post    = get_post($post_ID); 
        $content = $post->post_content;
        $length  = strlen($content);
        if ($length) {
            echo $length.' symbols';
        }
    }
}

add_filter('manage_posts_columns', 'len_columns_head');
add_action('manage_posts_custom_column', 'len_columns_content', 10, 2);

but now i need to add total count of symbols to column title like this: "Symbols, 123456 total". How can i achieve this? I have tried to add global variable to functions.php and add $length to it on every len_columns_content call, but that didn't work

  • Have you tried doing a var_dump() of $content to verify that it's a string? – WebElaine Jul 17 at 15:51
1

WebElaine, if you are asking about global variable, i am doing something like this:

global $total_len;

...
function len_columns_content($column_name, $post_ID) {
...
if ($length) {
    $total_len += $length;
    echo $length.' symbols'.'total: '.$total_len;
}
...

and in every string i have get $total_len equal $length, as if $total_len is not global

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.