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;

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

Count number of posts by author in a category

You could do this by creating a custom WP_Query and then counting it. $args = array( ‘author’ => 1, ‘cat’ => 5, ); $my_query = new WP_Query( $args ); $my_count = $my_query->post_count; Just change 1 and 5 to the Author ID and Category ID respectively. Alternatively you can use the category slug or author’s nice … Read more

Increasing post view count automatically [duplicate]

You can automatically add a custom field to each new post on publish (on change status to publish). And then set it’s value to a random number between 829 and 1013. Here is the function that will do just that. // Create custom field on post publish function wpse_custom_field_on_publish( $new, $old, $post ) { if … 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

Category and children post count

Checking Daniel Llewellyn code and WordPress’ WP_Query reference, I realized that we need to pass an array of array within the tax_query parameter. Otherwise, it’d just return all post counts. Here is the little modified code: if ( ! function_exists( ‘ipt_kb_total_cat_post_count’ ) ) : /** * Simple function to get category post count including all … Read more

Counting the posts of a loop (WP_Query)?

Some additional information, no need to count the posts again, because WP_Query already did that for you. To clarify this, some information from the Class Reference of WP_Query as found in the »Properties« section: $post_count The number of posts being displayed. $found_posts The total number of posts found matching the current query parameters What this … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş