I would like to create a shortcode to display the total of each of my custom type posts on the front page of my site - eg film reviews, messages, ebooks....
Is there a similar example that we can see?
I used this code:
// Get post count for films
add_shortcode('filmcount', 'film_count');
function post_count() {
$count_posts = wp_count_posts('film');
$published_posts = $count_posts->publish;
return $published_posts . ' ';
}
If you are writing custom shortcodes for this it really is a generic WordPress question that would be better posted on stack exchange.
You can do the same without shortcodes by creating a View for a post type such as 'film', and in the Loop Output section between the wpv-loop tags output the shortcode wpv-found-count which will display the number of posts published of that type.
You would probably want to output zero in the no-items-found section, and also check the option "Disable the wrapping DIV around the View" to output the clean post count without additional markup.
Hi, I have created a new View, but cannot get it to generate meaningful output - namely the total number of items. I can get the equivalent of a tag count cloud, but not the total. I do not have an account on Stack Exchange, and they are not allowing new account creation. Sorry. If this is not possible, I can reedit the home page every time I add new items, but that is very tedious. Probably less so than pursuing this?!
Sorry, I spoke a bit too soon, you of course shouldn't output the shortcode withing the loop as it will output it multiple times, you just want to output it once, so just inside the wpv-items-found section but not within the wpv-loop tags.
My issue is resolved now. Thank you!
Although adding the ability to show the totals to the public could be added as a feature request - something like the (edited) information displayed in the At a Glance widget by typewheel.xyz (Glance That)