Count posts or custom post types from last 24 hours (or from today)

You can write your own function (add it to functions.php file: function get_posts_count_from_last_24h($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, date(‘Y-m-d H:i:s’, strtotime(‘-24 hours’)) ) ); return $numposts; } function get_posts_count_from_today($post_type=”post”) { global $wpdb; $numposts = $wpdb->get_var( … Read more

How to cache a shortcode functions output?

You might have a look at the WordPress Transient API. You should be able to store your shortcode output $total_network with set_transient( ‘my_shortcode_cache’, $total_network, WEEK_IN_SECONDS ); where WEEK_IN_SECONDS is a built in constant equal to 604800. You can then fetch it with: get_transient( ‘my_shortcode_cache’ ); If you need it to work network wide there exists … Read more

Total word count for posts by one author

I use a plug-in called Post Word Count to sum the total number of published words across my entire site … then again, I’m the only author, so this is a pretty simple example. But you could start with this plug-in and add a filter that changes the query based on the author’s ID. Basically: … Read more

Count the number of images uploded on the website

There’s a handy built-in function, namely wp_count_attachments(). We can filter out images with wp_count_attachments( $mime_type=”image” ) that returns an object like: stdClass Object ( [image/gif] => 9 [image/jpeg] => 121 [image/png] => 20 [image/x-icon] => 6 [trash] => 0 ) So we can use the one-liner: $count = array_sum( (array) wp_count_attachments( $mime_type=”image” ) ); for … Read more

WP 3.5 and Galleries – how to count images?

This works: $images = get_children( array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘numberposts’ => 999 )); if ( $images ) { $total_images = count( $images ); } The variable $total_images will hold the count of images in your gallery.

Taxonomy count per Post type

I needed to get the number of post per type per term so i created this small function: function get_term_post_count_by_type($term,$taxonomy,$type){ $args = array( ‘fields’ =>’ids’, //we don’t really need all post data so just id wil do fine. ‘posts_per_page’ => -1, //-1 to get all post ‘post_type’ => $type, ‘tax_query’ => array( array( ‘taxonomy’ => … Read more

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