• Resolved Beee

    (@beee)


    on https://www.porntrialz.com (NSFW) I’m counting published posts in some categories, so I use this code to exclude some (hence the -127)

    <?php $num_posts = wp_count_posts( 'post' ); ?>
    <?php	$num = number_format_i18n( $num_posts->publish ); ?>
    <?php	$num = $num - '127'; ?>
    
    <div class="desk"><span>We now have <b><?php echo "$num"; ?> trials</b></span> in our database and growing each day.</div>

    When I had 999 posts there was no problem. Now I have 1000 published posts, so it becomes 1,000

    I can’t subtract 127 properly since it counts 1,000 as 0 so it displays -127 instead of 873

Viewing 1 replies (of 1 total)
  • Thread Starter Beee

    (@beee)

    found the solution. Where it says 127 is actualy a variable called $excl (number of posts to exclude)

    this works

    <?php $num_posts = wp_count_posts( 'post' ); ?>
    <?php $num = number_format_i18n( $num_posts->publish - $excl ); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Trouble with counting posts’ is closed to new replies.