How to update incorrect post count in taxonomy?

It only took 3.5-years for someone to be put into the position of @robert-andrews to chase down the post count problem. While having the same problem (and misinterpretation), I ran across your post yesterday in my search for answers. Nothing good really turned up. So, I was forced to trace the code and take the … Read more

Count user posts by type and date

The elegant way to get posts out of the database is to use wp_query. It has all the filters you need: function wpse70323_count_user_posts_by_type( $userid, $post_type, $year, $month, $day ) { $query = new WP_Query( array( ‘author’ => $userid, ‘post_type’ => $post_type, ‘date_query’ => array( array( ‘year’ => $year, ‘month’ => $month, ‘day’ => $day, ), … Read more

How to count current user’s pages?

Look what count_user_posts() does inside and change the post type parameter: global $wpdb; // ‘page’ is the important part here $where = get_posts_by_author_sql(‘page’, true, $userid); $count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” ); Then you change your snippet to: global $wpdb; $user = wp_get_current_user(); $where = get_posts_by_author_sql( ‘page’, true, $user->ID ); $count = $wpdb->get_var( … Read more

Show weekly posts statistic in WordPress

You already have the total post, so in order to get the total post within the last week, it’s better if you do this on your functions.php file: function get_posts_count_from_last_week($post_type=”post”) { global $wpdb; $numposts = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(ID) “. “FROM {$wpdb->posts} “. “WHERE “. “post_status=”publish” “. “AND post_type= %s “. “AND post_date> %s”, $post_type, … Read more

Comment Count for each Comment Author

Place this in your functions.php theme file: <?php function ps_count_user_comments() { global $wpdb; $count = $wpdb->get_var( ‘SELECT COUNT(comment_ID) FROM ‘ . $wpdb->comments. ‘ WHERE comment_author_email = “‘ . get_comment_author_email() . ‘” AND comment_approved = “1” AND comment_type IN (“comment”, “”)’ ); return $count . ‘ comments’; } ?> This code will count the author comments … Read more

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