Count user posts by type and date

I use the following code to count user posts by specific post type: function count_user_posts_by_type( $userid, $post_type ) { global $wpdb; $where = get_posts_by_author_sql( $post_type, TRUE, $userid ); $count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” ); return apply_filters( ‘get_usernumposts’, $count, $userid ); } // Echo Count echo count_user_posts_by_type( $user_ID, ‘reports’ ); Looking for an … Read more

Audio or playlist shortcode condition according to the amount of files on attachment page

My reason for doing this is for a music & entertainment site where users will have the ability to share music and videos on other websites via embed code. I’m using the audio.php and video.php attachment pages to load the default MediaElement.js HTML5 Player with all the attached media from it’s parent post. I then … Read more

Counting the occurrences / frequency of array elements

In Javascript, I’m trying to take an initial array of number values and count the elements inside it. Ideally, the result would be two new arrays, the first specifying each unique element, and the second containing the number of times each element occurs. However, I’m open to suggestions on the format of the output. For … Read more

How to count current user’s pages?

There are a lot of answers on how to count users posts by using: <?php if ( is_user_logged_in() ) { global $wpdb; $user = wp_get_current_user(); $where = get_posts_by_author_sql( ‘page’, true, $user->ID ); $count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” ); ?> //option 1 <h2>Hey <?php echo $current_user->display_name ?>, check your page here: {page title … Read more

Count posts in category including child categories

I have found this code somewhere, it counts posts but only which are under specific category. I would appreciate if someone could expand this so it would count all posts which also belong to its child categories? function wp_get_cat_postcount($id) { $cat = get_category_by_slug( $id ); $count = (int)$cat->count; $taxonomy = ‘category’; $args = array( ‘child_of’ … Read more