Can I get an authors total post count across all blogs in a multisite?

I'm using the Advanced Author Bio plugin by Abhik. In my author bio on each blog it displays my bio from my super-admin profile but it lists the total number of posts for that blog only. Is it possible to use something that would create the same effect but list my total number of posts across the entire multisite?

Thanks,
Larry

  • Vaughan

    Hi @lbartley,

    You would need to custom code this in the plugin.

    You will need to change the query for the post count.

    Something like the following maybe.

    <?php
    
    $sites = wp_get_sites( 'network_id' );
    $total = 0;
    foreach ($sites as $site) {
       switch_to_blog($site['blog_id']);
       $val = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s",time()) . "'");
       $total += $val;
       restore_current_blog();
    }
    echo $total;

    Hope this helps

  • lbartley

    Thanks Vaughn- I'm not much of a coder but I'm trying to learn. The code for the plugin is attached below. Can you point me to where I would want to insert or overwrite with the code you suggested?

    <?php
    /*
    Plugin Name: Advanced Author Bio
    Plugin URI: http://www.itsabhik.com/advanced-author-bio-wordpress-plugin/
    Description: Adds a short author bio after every single post on your blog. Also, adds Facebook, Twitter, Google+ and LinkedIn field in author's profile.
    Version: 3.1
    Author: Abhik
    Author URI: http://www.itsabhik.com
    License: GPL2
    */
    ?>
    <?php
    function aab_style() {
    echo ( '<link rel="stylesheet" type="text/css" href="'. WP_PLUGIN_URL . '/advanced-author-bio/style.css">' );
    }

    function aab_contactmethods( $contactmethods ) {
    unset($contactmethods['jabber']);
    unset($contactmethods['yim']);
    unset($contactmethods['aim']);
    $contactmethods['websitename'] = 'Website Title';
    $contactmethods['googleplus'] = 'Google+ Profile';
    $contactmethods['linkedin'] = 'LinkedIn Profile';
    $contactmethods['twitter'] = 'Twitter Profile';
    $contactmethods['facebook'] = 'Facebook Profile';
    $contactmethods['pinterest'] = 'Pinterest Profile';
    $contactmethods['youtube'] = 'YouTube Profile';
    $contactmethods['flickr'] = 'Flickr Profile';
    $contactmethods['yahoo'] = 'Yahoo Profile';
    $contactmethods['stumble'] = 'StumbleUpon Profile';
    return $contactmethods;
    }

    function aab_author_meta($content){
    global $post;
    $email = get_the_author_meta('email');
    $default = WP_PLUGIN_URL . '/advanced-author-bio/images/default.png';
    $size = 70;
    $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
    $aab_author = array();
    $aab_author['name'] = get_the_author();
    $aab_author['numberofposts'] = number_format_i18n(get_the_author_posts());
    $aab_author['authorpage'] = get_author_posts_url(get_the_author_meta( 'ID' ));
    $aab_author['description'] = get_the_author_meta('description');
    $aab_author['twitter'] = get_the_author_meta('twitter');
    $aab_author['facebook'] = get_the_author_meta('facebook');
    $aab_author['googleplus'] = get_the_author_meta('googleplus');
    $aab_author['linkedin'] = get_the_author_meta('linkedin');
    $aab_author['website'] = get_the_author_meta('url');
    $aab_author['gravatar'] = get_avatar(get_the_author_meta('email'), '50');
    $aab_author['websitename'] = get_the_author_meta('websitename');
    $aab_author['firstname'] = get_the_author_meta('first_name');
    $aab_author['youtube'] = get_the_author_meta('youtube');
    $aab_author['flickr'] = get_the_author_meta('flickr');
    $aab_author['pinterest'] = get_the_author_meta('pinterest');
    $aab_author['yahoo'] = get_the_author_meta('yahoo');
    $aab_author['stumble'] = get_the_author_meta('stumble');

    if(!is_feed() && !is_home() && !is_404() && !is_archive() && !is_page() && !is_category()) {
    $content .='<div id="authorboxbody"><div class="authorinfo">';
    $content .='<img class="gravatar" src="'.$grav_url.'" alt="" />';
    $content .='<p class="authorname">Post By '.$aab_author['name'].' (<span style="text-decoration:underline;">'.$aab_author['numberofposts'].' Posts</span>:wink:</p>';
    $content .='<p class="description">'.$aab_author['description'].'</p>';
    if ($aab_author['website']) {
    $content .='<p class="website">Website: → '.$aab_author['websitename'].'</p>'; }
    $content .='</div><div class="authorsocial">';
    $content .='<p>Connect</p>';
    $content .='<div class="socialicons">';

    if ($aab_author['facebook']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/facebook.png" alt="" />'; }
    if ($aab_author['twitter']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/twitter.png" alt="" />'; }
    if ($aab_author['googleplus']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/googleplus.png" alt="" />'; }
    if ($aab_author['linkedin']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/linkedin.png" alt="" />'; }
    if ($aab_author['pinterest']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/pinterest.png" alt="" />'; }
    if ($aab_author['flickr']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/flickr.png" alt="" />'; }
    if ($aab_author['youtube']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/youtube.png" alt="" />'; }
    if ($aab_author['pinterest']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/pinterest.png" alt="" />'; }
    if ($aab_author['yahoo']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/yahoo.png" alt="" />'; }
    if ($aab_author['stumble']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/stumbleupon.png" alt="" />'; }

    $content .='</div></div>';
    $content .='<div class="clear"></div></div>';
    }
    return $content;
    }
    remove_filter('pre_user_description', 'wp_filter_kses');
    add_filter( 'pre_user_description', 'wp_filter_post_kses' );
    add_filter('user_contactmethods','aab_contactmethods',10,1);
    add_action('wp_head', 'aab_style');
    add_filter ('the_content', 'aab_author_meta');
    ?>

  • Vaughan

    Hi,

    Can you try replacing with the following:

    <?php
    /*
    Plugin Name: Advanced Author Bio
    Plugin URI: http://www.itsabhik.com/advanced-author-bio-wordpress-plugin/
    Description: Adds a short author bio after every single post on your blog. Also, adds Facebook, Twitter, Google+ and LinkedIn field in author's profile.
    Version: 3.1
    Author: Abhik
    Author URI: http://www.itsabhik.com
    License: GPL2
    */
    ?>
    <?php
    function aab_style() {
    echo ( '<link rel="stylesheet" type="text/css" href="'. WP_PLUGIN_URL . '/advanced-author-bio/style.css">' );
    }
    
    function aab_contactmethods( $contactmethods ) {
    unset($contactmethods['jabber']);
    unset($contactmethods['yim']);
    unset($contactmethods['aim']);
    $contactmethods['websitename'] = 'Website Title';
    $contactmethods['googleplus'] = 'Google+ Profile';
    $contactmethods['linkedin'] = 'LinkedIn Profile';
    $contactmethods['twitter'] = 'Twitter Profile';
    $contactmethods['facebook'] = 'Facebook Profile';
    $contactmethods['pinterest'] = 'Pinterest Profile';
    $contactmethods['youtube'] = 'YouTube Profile';
    $contactmethods['flickr'] = 'Flickr Profile';
    $contactmethods['yahoo'] = 'Yahoo Profile';
    $contactmethods['stumble'] = 'StumbleUpon Profile';
    return $contactmethods;
    }
    
    function aab_author_meta($content){
    global $post;
    $email = get_the_author_meta('email');
    $default = WP_PLUGIN_URL . '/advanced-author-bio/images/default.png';
    $size = 70;
    $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
    $aab_author = array();
    
    $user_blogs = get_blogs_of_user( the_author_meta('ID') );
    $post_total = 0;
    foreach ($user_blogs AS $user_blog) {
        switch_to_blog($user_blog->userblog_id);
        $post_total += get_the_author_posts();
    }
    restore_current_blog();
    
    $aab_author['name'] = get_the_author();
    $aab_author['numberofposts'] = number_format_i18n($post_total);
    $aab_author['authorpage'] = get_author_posts_url(get_the_author_meta( 'ID' ));
    $aab_author['description'] = get_the_author_meta('description');
    $aab_author['twitter'] = get_the_author_meta('twitter');
    $aab_author['facebook'] = get_the_author_meta('facebook');
    $aab_author['googleplus'] = get_the_author_meta('googleplus');
    $aab_author['linkedin'] = get_the_author_meta('linkedin');
    $aab_author['website'] = get_the_author_meta('url');
    $aab_author['gravatar'] = get_avatar(get_the_author_meta('email'), '50');
    $aab_author['websitename'] = get_the_author_meta('websitename');
    $aab_author['firstname'] = get_the_author_meta('first_name');
    $aab_author['youtube'] = get_the_author_meta('youtube');
    $aab_author['flickr'] = get_the_author_meta('flickr');
    $aab_author['pinterest'] = get_the_author_meta('pinterest');
    $aab_author['yahoo'] = get_the_author_meta('yahoo');
    $aab_author['stumble'] = get_the_author_meta('stumble');
    
    if(!is_feed() && !is_home() && !is_404() && !is_archive() && !is_page() && !is_category()) {
    $content .='<div id="authorboxbody"><div class="authorinfo">';
    $content .='<img class="gravatar" src="'.$grav_url.'" alt="" />';
    $content .='<p class="authorname">Post By '.$aab_author['name'].' (<span style="text-decoration:underline;">'.$aab_author['numberofposts'].' Posts</span>)</p>';
    $content .='<p class="description">'.$aab_author['description'].'</p>';
    if ($aab_author['website']) {
    $content .='<p class="website">Website: ? '.$aab_author['websitename'].'</p>'; }
    $content .='</div><div class="authorsocial">';
    $content .='<p>Connect</p>';
    $content .='<div class="socialicons">';
    
    if ($aab_author['facebook']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/facebook.png" alt="" />'; }
    if ($aab_author['twitter']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/twitter.png" alt="" />'; }
    if ($aab_author['googleplus']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/googleplus.png" alt="" />'; }
    if ($aab_author['linkedin']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/linkedin.png" alt="" />'; }
    if ($aab_author['pinterest']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/pinterest.png" alt="" />'; }
    if ($aab_author['flickr']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/flickr.png" alt="" />'; }
    if ($aab_author['youtube']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/youtube.png" alt="" />'; }
    if ($aab_author['pinterest']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/pinterest.png" alt="" />'; }
    if ($aab_author['yahoo']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/yahoo.png" alt="" />'; }
    if ($aab_author['stumble']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/stumbleupon.png" alt="" />'; }
    
    $content .='</div></div>';
    $content .='<div class="clear"></div></div>';
    }
    return $content;
    }
    remove_filter('pre_user_description', 'wp_filter_kses');
    add_filter( 'pre_user_description', 'wp_filter_post_kses' );
    add_filter('user_contactmethods','aab_contactmethods',10,1);
    add_action('wp_head', 'aab_style');
    add_filter ('the_content', 'aab_author_meta');
    ?>

    Hope this helps

  • Vaughan

    Hi Bob,

    Can you try the following.

    <?php
    /*
    Plugin Name: Advanced Author Bio
    Plugin URI: http://www.itsabhik.com/advanced-author-bio-wordpress-plugin/
    Description: Adds a short author bio after every single post on your blog. Also, adds Facebook, Twitter, Google+ and LinkedIn field in author's profile.
    Version: 3.1
    Author: Abhik
    Author URI: http://www.itsabhik.com
    License: GPL2
    */
    ?>
    <?php
    function aab_style() {
    echo ( '<link rel="stylesheet" type="text/css" href="'. WP_PLUGIN_URL . '/advanced-author-bio/style.css">' );
    }
    
    function aab_contactmethods( $contactmethods ) {
    unset($contactmethods['jabber']);
    unset($contactmethods['yim']);
    unset($contactmethods['aim']);
    $contactmethods['websitename'] = 'Website Title';
    $contactmethods['googleplus'] = 'Google+ Profile';
    $contactmethods['linkedin'] = 'LinkedIn Profile';
    $contactmethods['twitter'] = 'Twitter Profile';
    $contactmethods['facebook'] = 'Facebook Profile';
    $contactmethods['pinterest'] = 'Pinterest Profile';
    $contactmethods['youtube'] = 'YouTube Profile';
    $contactmethods['flickr'] = 'Flickr Profile';
    $contactmethods['yahoo'] = 'Yahoo Profile';
    $contactmethods['stumble'] = 'StumbleUpon Profile';
    return $contactmethods;
    }
    
    function aab_author_meta($content){
    global $post;
    $email = get_the_author_meta('email');
    $default = WP_PLUGIN_URL . '/advanced-author-bio/images/default.png';
    $size = 70;
    $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
    $aab_author = array();
    
    $user_blogs = get_blogs_of_user(get_the_author_meta('ID'));
    $post_total = 0;
    foreach ($user_blogs AS $user_blog) {
        switch_to_blog($user_blog->userblog_id);
        $post_total += get_the_author_posts();
    }
    restore_current_blog();
    $aab_author['name'] = get_the_author();
    $aab_author['numberofposts'] = number_format_i18n($post_total);
    $aab_author['authorpage'] = get_author_posts_url(get_the_author_meta( 'ID' ));
    $aab_author['description'] = get_the_author_meta('description');
    $aab_author['twitter'] = get_the_author_meta('twitter');
    $aab_author['facebook'] = get_the_author_meta('facebook');
    $aab_author['googleplus'] = get_the_author_meta('googleplus');
    $aab_author['linkedin'] = get_the_author_meta('linkedin');
    $aab_author['website'] = get_the_author_meta('url');
    $aab_author['gravatar'] = get_avatar(get_the_author_meta('email'), '50');
    $aab_author['websitename'] = get_the_author_meta('websitename');
    $aab_author['firstname'] = get_the_author_meta('first_name');
    $aab_author['youtube'] = get_the_author_meta('youtube');
    $aab_author['flickr'] = get_the_author_meta('flickr');
    $aab_author['pinterest'] = get_the_author_meta('pinterest');
    $aab_author['yahoo'] = get_the_author_meta('yahoo');
    $aab_author['stumble'] = get_the_author_meta('stumble');
    
    if(!is_feed() && !is_home() && !is_404() && !is_archive() && !is_page() && !is_category()) {
    $content .='<div id="authorboxbody"><div class="authorinfo">';
    $content .='<img class="gravatar" src="'.$grav_url.'" alt="" />';
    $content .='<p class="authorname">Post By '.$aab_author['name'].' (<span style="text-decoration:underline;">'.$aab_author['numberofposts'].' Posts</span>)</p>';
    $content .='<p class="description">'.$aab_author['description'].'</p>';
    if ($aab_author['website']) {
    $content .='<p class="website">Website: ? '.$aab_author['websitename'].'</p>'; }
    $content .='</div><div class="authorsocial">';
    $content .='<p>Connect</p>';
    $content .='<div class="socialicons">';
    
    if ($aab_author['facebook']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/facebook.png" alt="" />'; }
    if ($aab_author['twitter']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/twitter.png" alt="" />'; }
    if ($aab_author['googleplus']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/googleplus.png" alt="" />'; }
    if ($aab_author['linkedin']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/linkedin.png" alt="" />'; }
    if ($aab_author['pinterest']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/pinterest.png" alt="" />'; }
    if ($aab_author['flickr']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/flickr.png" alt="" />'; }
    if ($aab_author['youtube']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/youtube.png" alt="" />'; }
    if ($aab_author['pinterest']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/pinterest.png" alt="" />'; }
    if ($aab_author['yahoo']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/yahoo.png" alt="" />'; }
    if ($aab_author['stumble']) {
    $content .='<img src="'.WP_PLUGIN_URL.'/advanced-author-bio/images/stumbleupon.png" alt="" />'; }
    
    $content .='</div></div>';
    $content .='<div class="clear"></div></div>';
    }
    return $content;
    }
    remove_filter('pre_user_description', 'wp_filter_kses');
    add_filter( 'pre_user_description', 'wp_filter_post_kses' );
    add_filter('user_contactmethods','aab_contactmethods',10,1);
    add_action('wp_head', 'aab_style');
    add_filter ('the_content', 'aab_author_meta');
    ?>

    Hope this helps

  • Vaughan

    Hi,

    Not sure, has it ever?

    I see in the code for the plugin, it looks to come from line 75.

    $content .='<p class="website">Website: ? '.$aab_author['websitename'].'</p>'; } I haven't touched that line at all, that doesn't have a permalink attached to it at all and uses a ? in the code there.

    But I just opened up that original file you had in the plugin folder that was renamed, and saw there, the line was different.

    I have added that line to the file. Hopefully that should now be display how you want it.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.