User Published Post Count

Here are some different approaches: Fetch users with get_users() and paginate them with e.g. 10 per page. For each user, call WP_Query with date_query for the last 24 hours, else last week. Use author input argument and posts_per_page as 1 (we don’t need more) and get the total posts from WP_Query::found_posts. pros: Uses only WordPress … 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

Count custom post types with a specific meta value

1st. you need to add post_type to your query, then you need to filter meta_value with LIKE. Finaly, you need to add posts_per_page as -1 to get ALL posts. $args = array( ‘post_type’=> ‘books’, ‘meta_query’ => array( array( ‘key’ => ‘book_type’, ‘value’ => ‘Fiction’, ‘compare’ => ‘LIKE’, ) ), ); $query = new WP_Query($args); $fiction … Read more

Set font size automatically according to number of words in post

Filter ‘the_content’, count the words, and add the markup you need. You should not use str_word_count() because it has issues with numbers and utf-8. So let’s start with a word count function: /** * Alternative for str_word_count(). * * @link http://toscho.de/2012/php-woerter-zaehlen/ * @param string $str * @return int Number of words */ function t5_word_count( $str … 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

Count number of post in Taxonomy?

The function you are looking for is get_term() http://codex.wordpress.org/Function_Reference/get_term and the code would look something like this: $term = get_term( 1, ‘category’ );//for example uncategorized category echo ‘count: ‘. $term->count;

taxonomy list display custom post count

What makes this annoying is that the count is a wp_term_taxonomy table. So the way to do this is a custom query: function wpse340250_term_count( WP_Term $term, $post_type) { $q_args = [ ‘post_type’ => $post_type, ‘nopaging’ => true, // no limit, pagination ‘fields’ => ‘ids’, // only return post id’s instead of full WP_Post objects will … Read more

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more

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