WordPress.org

Ready to get started?Download WordPress

Forums

Draft posts showing up in wp-list authors (2 posts)

  1. elyonline
    Member
    Posted 9 years ago #

    Hi there,

    I noticed that when I list my authors with this tage:

    '<?php wp_list_authors('optioncount=1&show_fullname=1&hide_empty=1'); ?>'

    That it also shows the authors draft posts.

    How do I fix this?

    Thanks

  2. EvilBernd
    Member
    Posted 9 years ago #

    Hi there

    Try to change this function in functions.php (in the include-directory):

    function get_usernumposts($userid) {
    global $wpdb;
    return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid'");
    }

    to something like this: (this will count the number of published posts)

    function get_usernumposts($userid) {
    global $wpdb;
    return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_status = 'publish'");
    }

    or (to just count each non-draft post):

    function get_usernumposts($userid) {
    global $wpdb;
    return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_status <> 'draft'");
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.