Support » Themes and Templates » Showing Wrong Number of Posts

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • whooami

    (@whooami)

    Member

    $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

    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….

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Showing Wrong Number of Posts’ is closed to new replies.