Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having problems with counting posts of a custom post type called 'projects' and like to add a number to the count. We did some stuff which can't be shown in our portfolio but would like to add only as number.

Basically it goes as follow:

There are 22 published projects (custom posts type called 'projects') + 11 other projects (no posts) = echo 33 projects.

Edit:

I'm using this to get the wordpress counts:

<?php
            $count_posts = wp_count_posts('projects');
            $published_posts = $count_posts->publish;
            ?>

<?php // echo $published_posts  ?>

How do I get this working?

Thanks in advance.

share|improve this question
    
The 22 projects are published posts from the projects CPT? What are the 11 others? Unpublished posts? Planned projects with no presence in the DB? What? –  s_ha_dum Jun 6 '13 at 15:01
    
Hi s_ha_dum they are created projects but not in the database (and will never be). –  rwzdoorn Jun 6 '13 at 15:10
    
So how are you tracking them? You just want a count of posts plus a static number? –  s_ha_dum Jun 6 '13 at 15:11
    
I've editted my post question. I'm counting already the wordpress posts but need to add a static number (11) to count the total. –  rwzdoorn Jun 6 '13 at 15:13
add comment

1 Answer

up vote 2 down vote accepted

If you want to count posts of some custom post type, you can try out the WordPress function wp_count_posts()

In your case the custom post type is 'projects' so you might try this:

$count_projects = wp_count_posts( 'projects' );
$published_projects = $count_projects->publish;
$total = $published_projects + 11; // include your additional projects

You can read more about this function in the Codex here.

share|improve this answer
    
Thank you Birgire! Right answer. –  rwzdoorn Jun 6 '13 at 15:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.