Adding a posts count in archive pages

If the theme your’re using doesn’t do anything fancy, but uses the_archive_title() to render the “Lignano Sabbiadoro”, then you should be able to modify it with the get_the_archive_title filter. Something along these lines. add_filter(‘get_the_archive_title’, ‘my_get_the_archive_title_filter’, 10, 3); function my_get_the_archive_title_filter(string $title, string $original_title, string $prefix): string { if (! is_category()) { return $title; } $current_category = … Read more

Can I count every article following extracted meta value?

Use array_count_values() (untested): <?php $posts = get_posts( array( ‘numberposts’ => -1, ‘category_name’ => ‘bird’, ‘order’ => ‘ASC’, ) ); if ( $posts ) { foreach( $posts as $post ) { $species[] = get_post_meta( $post->ID, ‘species1’, true ); $species[] = get_post_meta( $post->ID, ‘species2’, true ); } } $species = array_filter( $species ); $counts = array_count_values( $species … Read more

Count the number of matching post names in foreach loop

I would get the count of a variable number of repeated titles by using an indexed array. $theposts = get_posts( array( ‘post_type’ => ‘post_subscriber’, ‘post_status’ => ‘publish’, ‘numberposts’ => -1, ) ); // project titles counter, outside the loop $project_titles = array(); foreach( $theposts as $p ): $project_name = get_post_meta($p->ID, ‘project’, true); echo ‘<ol>’; echo … Read more

Display post count on archive page in reverse order

You can give a try to this within a loop <?php echo $wp_query->found_posts – $wp_query->current_post ; ?> $wp_query->found_posts gives the total number of posts found matching the current query parameters. So the if there are 20 posts, result for each post should look like this For 1st post it will display 20, i.e. 20-0=20 For … Read more

Count images in post then add class if just one

Using @pascalvgemert’s suggestion as a starting point, I’m using the following script: jQuery(document).ready(function() { var imgCount = jQuery(“.single-post #content-left p a”).children(“img”).length; if (imgCount == 1) { jQuery(“img”).addClass(“lone-image”); } }); Works like a charm.

Count words for all posts by all authors

You will need a function to get all the published posts and count the words. function wpse410818_count_published_words() { $posts = new WP_Query(array( ‘post_type’ => array( ‘post’ ), ‘post_status’ => ‘publish’, )); $count = 0; //Starting words count if ( $posts->have_posts() ) { while ( $posts->have_posts() ) { $posts->the_post(); //Add to the word count $count += … Read more