Count Query by custom field
// WP_Query arguments $args = array( 'post_type' => array( 'invoices' ), 'post_status' => array( 'published' ), ); // The Query $count_active_projects = new WP_Query( $args ); // The Loop if ( $count_active_projects->have_posts() ) { while ( $count_active_projects->have_posts() ) { $count_active_projects->the_post(); // do something } } else { // no posts found } // Restore original Post Data wp_reset_postdata();