Total Word Count For Posts And Comments By One Author

Run a couple of queries and a code snippet to calculate the word count for the post content, comments content and tag names on each post. // This query will return the number of words in the post content $post_qry=”SELECT LENGTH(post_content) – LENGTH(REPLACE(post_content, ‘ ‘, ”))+1 from wp_posts where ID=”.$post_id; // This query will return … Read more

Show the author’s count of total amount of posts assign to a custom taxonomy term

/** * Get the author post count for a tax query. * * @link http://wordpress.stackexchange.com/q/159160/1685 * * @param array $tax_query * @return int */ function wpse_159160_get_author_posts_by_tax( $tax_query ) { global $wpdb; $where = get_posts_by_author_sql( ‘post’, true, get_post()->post_author ); $tax_query = new WP_Tax_Query( $tax_query ); $sql = $tax_query->get_sql( $wpdb->posts, ‘ID’ ); return ( int ) $wpdb->get_var( … Read more

Count number of published posts by type

If you prefer the $wpdb direct queries you can use something like this: global $wpdb; $count = $wpdb->get_var( “SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type=”code” and post_status=”publish”” ); echo $count; In the sql query above change the post_type to whatever you like. This will return count of published posts under specific post type only. If you … Read more

Count total number of post in foreach loop

Edit: Re-reading your question I noticed I may have mixed some things up, but the point remains that you should combine these separate queries performed inside the loop, by using variables inside the loop to create a comprehensive list of the query arguments that you can use to perform one query outside the loop. I’ve … Read more

How we count the user draft posts

The function count_user_posts only accepts a user ID so you arguments are never taken in consideration. Here is a simple function to get the count by status function count_user_posts_by_status($post_status=”publish”,$user_id = 0){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare( ” SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s AND post_author = %d”, $post_status, $user_id ) ); return … Read more

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