0

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.

4
  • 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, 2013 at 15:01
  • Hi s_ha_dum they are created projects but not in the database (and will never be).
    – rwzdoorn
    Jun 6, 2013 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, 2013 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, 2013 at 15:13

1 Answer 1

2

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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