Apr 21, 2021 6:51 am
Hello
Is it possible that in user activity the custom post types are added to the total blog articles written by a user?
Thanks
1 Reply
Apr 23, 2021 5:39 am
You should use this code. Put it in the functions.php file of your active WordPres theme or use the Code Snippets plugin to insert it into your website.
Don't forget to add custom post types in the $post_type = [....] array after the 'post'. Separate post types by comma, make sure you use the post type name not the post type titles. Post type names don't have upper case chars and spaces:
add_filter('get_usernumposts', 'wpforo_user_custom_post_type_count',10, 4);
function wpforo_user_custom_post_type_count( $count, $userid, $post_type, $public_only ){
$post_type = ['post']; //add comma separated custom post types['post', 'book', 'event',...]
if( function_exists('WPF') ){
global $wpdb;
if(is_wpforo_page()){
$where = get_posts_by_author_sql( $post_type, true, $userid, $public_only );
$custom_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
if( $custom_count ) return $custom_count;
return $count;
}
}
}