How can I get a count of the total posts of a given post type? I'm assuming there's a shortcode or a way to create a really simple View to display this.
If there's not a built-in way, please add it as a feature request and I'll just custom code it myself.
Thank you.
Hello,
You can try this:
1) Create a post view, query posts of given post type
2) in section "Limit and Offset", Use option "Display no limit items"
3) in section "Loop Editor", within shortcodes [wpv-items-found] ... [/wpv-items-found]
display only shortcode [wpv-found-count]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count
Above view should be able to output total post count of post type too.
That worked great, except it's weird that the loop part is still required: hidden link
Greedy request... is there a way in Views to round it? For example, if the count is 21-30, I want it to display "More than 20 reviews," If it's 31-40, I want it to display "More than 30 reviews", etc.
Yes, you are right, the loop part is still required, you can let it here with empty.
For the new question:
if the count is 21-30, I want it to display "More than 20 reviews," If it's 31-40, I want it to display "More than 30 reviews", etc.
You can use [wpv-conditional] shortcode to check the [wpv-found-count] shortcode's value, then display what you want, for example:
[wpv-conditional if="( '[wpv-found-count]' > 20 )"]
More than 20 reviews
[/wpv-conditional ]
More help:
hidden link
Is there something that doesn't require me to write all the specific conditions, just rounds as requested? Or would custom PHP be required for that?
Yes, you are right, it needs custom PHP codes, for example, you can create a custom shortcode with a PHP function:
https://codex.wordpress.org/Function_Reference/add_shortcode
in this PHP function, get the [wpv-found-count] shortcode's value:
https://developer.wordpress.org/reference/functions/do_shortcode/
And get the value of "rounds as requested":
hidden link