Notifications
Clear all

Script [Solved] CPT added to total blog articles in user activity

2 Posts
2 Users
1 Likes
825 Views
Posts: 10
Topic starter
(@jarruego)
Eminent Member
Joined: 3 years ago

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
Robert
Posts: 10499
Admin
(@robert)
Support Team
Joined: 8 years ago

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;
}
}
}