I used to use the plugin "Admin Columns" to add extra columns to the users columns in the WordPress backend. Now this is something that the plugin can't do:
Show only the posts that have at least 1200 characters.
Very special but it would be great.
This is what I got by now:
function count_manage_users_custom_column($output = '', $column_name, $user_id) {
global $wpdb;
if( $column_name !== 'post_chars_count' )
return;
$where = get_posts_by_author_sql( 'post', true, $user_id );
$result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
return '<a href="' . admin_url("edit.php?post_type=post&author=$user_id") . '"
title="Post Type Count">' . $result . '</a>';
}
add_filter('manage_users_custom_column', 'count_manage_users_custom_column', 10, 3);
function count_manage_users_columns($columns) {
$columns['post_chars_count'] = __( 'Articles > 1200 chars', 'textdomain' );
return $columns;
}
add_filter('manage_users_columns', 'count_manage_users_columns');
It shows a new column that shows the posts that the user has published. But it shows all 3 articles, I need it to show only the one article that has > 1200 characters.
Any idea?
CodePudding user response:
I'm not sure what exactly "get_posts_by_author_sql" outputs, so you might be able to append AND length(post_content) > 1200
to the current $where clause.
This should definitely work though:
$sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author=%d AND post_type=%s AND length(post_content)>%d";
$result = $wpdb->get_var($wpdb->prepare($sql, $user_id, 'post', 1200));