AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

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

2 Posts
2 Users
1 Reactions
1,752 Views
Posts: 10
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@jarruego)
Eminent Member
Joined: 5 years ago
[#16570]

Hello

Is it possible that in user activity the custom post types are added to the total blog articles written by a user?

Thanks

Screenshot 1

1 Reply
Robert
Posts: 10749
Admin
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@robert)
Support Team
Joined: 3 months 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;
}
}
}

Share: