Count user posts and store the number for later use

You can use update_user_meta() to add information to a user’s meta fields, and count_user_posts() to get an initial count. So, for instance: <?php add_action( ‘new_to_publish’, ‘wpse96358_author_count’ ); add_action( ‘draft_to_publish’, ‘wps396358_author_count’ ); function wpse96358_author_count() { global $post; // get initial count $single = true; $author_count = get_user_meta( $post->post_author, ‘author_count’, $single ); if ( strlen( $author_count ) … Read more

Counting posts by certain author with custom taxonomy

$args = array( ‘taxonomy’ => ‘special’, ‘posts_per_page’ => -1, ‘author’ => 2 ); $author_category_posts = new WP_Query($args); $count_of_posts_by_author = $author_category_posts->post_count; You can fetch the number of posts made by that author in specific taxonomy.

Display amount of pending posts in back/front end

Easy native SQL query: global $wpdb; $sql = <<<SQL SELECT post_status, COUNT( * ) AS count FROM {$wpdb->posts} WHERE post_status=”pending” SQL; $result = $wpdb->get_results( $sql ); The result will be something like + ———– + —– + | post_status | count | + ———– + —– + | pending | 158 | + ———– + … Read more

$count_posts->draft & published

In this line you are getting only the count of published items (obviously!!!!): $published_projects = $count_projects->publish; You should do something like this: $count_projects = wp_count_posts( ‘apps’ ); $published_projects = $count_projects->publish; $draft_projects = $count_projects->draft; $total = $published_projects + $draft_projects; More details and examples in wp_count_posts() reference.

Order terms by count – missing terms

By default hide_empty is true for get_terms. So i guess you must be missing terms which do not have posts. Try this, <?php $terms = get_terms(“autorzy”, array(‘orderby’ => ‘count’, ‘order’ => ‘DESC’,’hide_empty’=>0 )); $count = count($terms); if ( $count > 0 ){ echo “<div>”; foreach ( $terms as $term ) { ?> <?php echo $term->name; … Read more

Taxonomy term count

You can use WP_Query Methods and Properties to accomplish this. $wp_query->found_posts will return the amount of posts within the term while $wp_query->queried_object->name will return the name of the term currently displayed. You can now just paste all these together to display 18 free resources $taxcount = $wp_query->found_posts; $taxname = $wp_query->queried_object->name; printf(__( ‘%s %s resources’ ), … Read more

How to Define Custom Number of Items in Comment Feed

There’s a filter for that! The filter comment_feed_limit can be used to adjust the LIMIT clause directly. By default, the option from Settings -> Reading is used (“Syndication feeds show the most recent”), but that’s used for other feeds as well. The comment_feed_limit filter is used exclusively for comment feeds. add_filter( ‘comment_feed_limits’, ‘wpse150187_comment_feed_limits’ ); function … Read more

Echo the number of posts being displayed

rearrange your code and use post_count; example: <?php $movieNumber = 1; $today = date(‘Ymd’); $posts = array ( ‘post_type’ => ‘movie’, ‘posts_per_page’ => -1, ); $loop = new WP_Query( $posts ); ?> <div id=”posters<?php echo $loop->post_count; ?>”> <?php while ( $loop->have_posts() ) : $loop->the_post(); …etc…

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