WordPress.org

Ready to get started?Download WordPress

Forums

Showing Wrong Number of Posts (3 posts)

  1. Altstatten
    Member
    Posted 7 years ago #

    The theme I'm using is showing a post count of 39 when it should be 18. Weird.

    Here's the site: http://www.marketingmeasure.com

    Here's the code:

    <?php
    $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
    if (0 < $numposts) $numposts = number_format($numposts);

    $numcmnts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
    if (0 < $numcmnts) $numcmnts = number_format($numcmnts);
    ?>
    *********************************************************

    Obviously the code is seeing something incorrectly. Any takers??
    ***********************************************

    Update: I counted and I have 18 posts and 21 pages, hence the 39!

    So how do I get this code to recognize only the posts?

  2. whooami
    Member
    Posted 7 years ago #

    $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
    if (0 < $numposts) $numposts = number_format($numposts);
    $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
    if (0 < $numcomms) $numcomms = number_format($numcomms);

    youre not specifying whether or not to count pages. Notice that my code is looking for a specific post_type?

    That, btw, comes straight of 2.1.3's /wp-admin/index.php

  3. Altstatten
    Member
    Posted 7 years ago #

    You're right. Copied and pasted the correctly written code from your aforementioned file into mine and it worked perfectly.

    Now if I could just get these kool-aid stains out of the carpet....

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags