Skip Navigation

[Resuelto] Shortcode for total post count of a post type

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

How can I get a count of the total posts of a given post type?

Solution:

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 shortcode [wpv-found-count]

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count

This support ticket is created hace 5 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Etiquetado: ,

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por Clifford hace 5 años, 10 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#1178671

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.

#1178895

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.

#1179357

That worked great, except it's weird that the loop part is still required: enlace oculto

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.

#1179524

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:
enlace oculto

#1179729

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?

#1179766

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":
enlace oculto

#1179807

Very good. Thank you.