Skip Navigation

[Resolved] Shortcode to count posts

This support ticket is created 4 years, 11 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 4 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1402541
Screenshot_1.jpg

Hi,
I have a job website where publishes job news as custom job posts. With the help of your support team, I have created one page that filters out the job posts based on another post-relationship. See the page here: hidden link
Now I want a shortcode to count the no. of posts on this particular page.
And also the Grand total of the 'Total No. of Vacancies' (these are also created with shortcodes) in those posts (See the screenshot).

Please help. Thank you.

#1402903

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You can display the count of how many posts are returned by a View with the wpv-found-count shortcode: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count

Insert that in the Loop Editor section of your View where you want the count to appear.

Regarding the Grand Total, this is rather more complex than displaying the sum of field values from a repeatable field group for a single post.

If you wanted to display this total towards the bottom of the page, at the end of the View and as long as there was no pagination involved, it wouldn't be too difficult to come up with a solution.

If you want to display the total towards the top of the page before the View output then that involves a more complex query that effectively recreates the View, iterates over the matching posts, gets the count for each individual post in a manner similar to the custom shortcode provided previously, and then sums those.

But that's well outside of support, you would need to hire a developer for that if you are not able to adapt that existing code yourself.