Count total number across post types

Why not just get the count for each post type and sum them? function get_all_them_ven_posts(){ $count= 0; $post_types = [ ‘postType1’, ‘postType2’, ‘postType3’ ]; foreach( $post_types as $post_type ) { $count_posts = wp_count_posts( $post_type ); $count = $count + $count_posts->publish; } return $count; }

What is the best way to count and display the number of posts?

Another solution would be to use an ordered list. $my_query = new WP_Query($args); if ( $my_query->have_posts() ) : echo ‘<ol style=”list-style:decimal”>’; while( $my_query->have_posts() ) : $my_query->the_post(); echo ‘<li><a href=”‘ . get_permalink( get_the_ID() ) . ‘”>’ . get_the_title() . ‘</a></li>’; endwhile; echo ‘</ol>’; endif;

Count all comments of a custom post type

How about direct sql with a simple subquery to first get all the post ids of your custom post type ex: function get_all_comments_of_post_type($post_type){ global $wpdb; $cc = $wpdb->get_var(“SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID in ( SELECT ID FROM $wpdb->posts WHERE post_type=”$post_type” AND post_status=”publish”) AND comment_approved = ‘1’ “); return $cc; } Usage: $total_comments = get_all_comments_of_post_type(‘some_post_type’);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)