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
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
Share Improve this question asked Jul 17, 2020 at 15:40 dmitrydmitry 111 bronze badge 1 |1 Answer
Reset to default 1WebElaine, 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
var_dump()
of$content
to verify that it's a string? – WebElaine Commented Jul 17, 2020 at 15:51