function number_postpercat($idcat, $post_status='publish') { global $wpdb; $result=$wpdb->get_col("SELECT c.post_id FROM {$wpdb->post2cat} c INNER JOIN {$wpdb->posts} p ON c.post_id = p.id WHERE c.category_id = $idcat AND p.post_status='$post_status'"); $number=count($result); echo $number; }