Custom Post Type Category List & Post Count
$tax_term->count should contain the number of posts in the category. You may need to add the $args parameter if you want to include subcategory counts. Docs: get_terms()
$tax_term->count should contain the number of posts in the category. You may need to add the $args parameter if you want to include subcategory counts. Docs: get_terms()
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
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
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
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
You can use get_terms to get the list of all terms associated with a taxonomy. Once you have all the separate terms, you can use $term->name to display the name of the term and $term->count to retrieve the amount of posts inside that specific term. Here is a slightly modified version of the code found … Read more
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
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;
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
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