Count posts within a custom post type and specific taxonomy and terms?

I’m looking to count how many post live within the custom post type called “videos”, but only the ones from the category called “work”. <?php $count_posts = wp_count_posts(‘videos’); echo $count_posts->publish; // ?> How can I adjust the above code to accomplish this? Thanks! 7 s 7 An alternative solution using WP_Query would be: $args = … Read more

How to sort a list of objects based on an attribute of the objects?

I have a list of Python objects that I want to sort by a specific attribute of each object: >>> ut [Tag(name=”toe”, count=10), Tag(name=”leg”, count=2), …] How do I sort the list by .count in descending order? 8 s 8 # To sort the list in place… ut.sort(key=lambda x: x.count, reverse=True) # To return a … Read more

Counting the posts of a loop (WP_Query)?

I tried this way to display NO of post: <?php $news_2 = new WP_Query( array (‘post_type’=> ‘jobs’,’posts_per_page’=> ’10’ , ‘meta_key’ => ‘status_for_jobs’,’meta_value’ => ‘1’) ); if ( $news_2->have_posts() ) { while ( $news_2->have_posts() ) { $news_2->the_post(); $count = $news_2->post_count; ?> <li><h3><a href=”https://wordpress.stackexchange.com/questions/139614/<?php the_permalink(); ?>”><?php the_title(); ?></a></h3></li> <?php } } ?> <?php wp_reset_query(); ?> if the … Read more

Count the number of occurrences of a character in a string

How do I count the number of occurrences of a character in a string? e.g. ‘a’ appears in ‘Mary had a little lamb’ 4 times. 2 25 str.count(sub[, start[, end]]) Return the number of non-overlapping occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpreted as in slice notation. … Read more

How to efficiently count the number of keys/properties of an object in JavaScript

What’s the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object? I.e., without doing: var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) ++count; (Firefox did provide a magic __count__ property, but this was removed somewhere around version 4.) 20 20 … Read more