0

Currently our portfolio is stacking up a lot and want to show a few projects less instead of showing all. Still, I'd like to show an indication how many projects we did in total. Currently I have the following code and need to count the drafts & published posts.

        $count_projects = wp_count_posts( 'apps' );
        $published_projects = $count_projects->publish;
        $total = $published_projects + 11;

How can I count all drafts & published posts together?

1 Answer 1

1

In this line you are getting only the count of published items (obviously!!!!):

$published_projects = $count_projects->publish;

You should do something like this:

$count_projects = wp_count_posts( 'apps' );
$published_projects = $count_projects->publish;
$draft_projects = $count_projects->draft;
$total = $published_projects + $draft_projects;

More details and examples in wp_count_posts() reference.

0

Your Answer

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

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