Notifications
Clear all

Limited Support

Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed. We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.

 

How to add author posts' view count in author page

0 Posts
1 Users
0 Reactions
4,311 Views
(@varos)
Estimable Member
Joined: 9 years ago
Posts: 141
Topic starter  

Dear users,

Please use this code and make sure that your WordPress is 4.1 or higher version:

add_filter('get_the_archive_title', 'apsw_the_archive_title');

if (!function_exists('apsw_the_author')) {
Β Β Β  function apsw_the_archive_title($title) {
Β Β Β Β Β Β Β  global $wpdb, $post;
Β Β Β Β Β Β Β  if ($wpdb && $post && $post->post_author && is_author()) {
Β Β Β Β Β Β Β Β Β Β Β  $sql = "SELECT SUM(`stats`.`view_count`) FROM `" . $wpdb->prefix . "sw_statistics` AS `stats` INNER JOIN `" . $wpdb->prefix . "posts` AS `p` ON `stats`.`post_id` = `p`.`ID` WHERE `p`.`post_author` = %d;";
Β Β Β Β Β Β Β Β Β Β Β  $sql = $wpdb->prepare($sql, $post->post_author);
Β Β Β Β Β Β Β Β Β Β Β  $userPostsViewsCount = $wpdb->get_var($sql);
Β Β Β Β Β Β Β Β Β Β Β  if ($userPostsViewsCount) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  $title .= " posts views($userPostsViewsCount)";
Β Β Β Β Β Β Β Β Β Β Β  }
Β Β Β Β Β Β Β  }
Β Β Β Β Β Β Β  return $title;

Β Β Β  }
}

   
Quote
Share:
Scroll to top