Skip Navigation

[Resolved] Custom post type statistics in view

This support ticket is created 2 years, 10 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)

This topic contains 4 replies, has 2 voices.

Last updated by tomasP 2 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#2274489

Hello,
I have a site with CPT called Events.
Each Event has custom fields with venue name, event date, event genre, etc.

I have managed to group entries based on venue name (hidden link) and display and filter some data. But I need to extract statistics based on custom fields - e.g. Total number of events is: 188
1) Venue 1 hosted 23 events during certain period which is X per cent of [wpv-found-count]
2) There were 16 events marked as "rock" genre, which is Y per cent of [wpv-found-count]
...
Could you kick me into a right direction how to achieve this, please?

Thanks in advance,
Tom

#2274725

Nigel
Supporter

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

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

Hi Tom

You'll need custom code for this, and I expect you'd probably need to write several custom shortcodes.

Will the context always be a View listing all events? But you don't necessarily want to display these things for every iteration (i.e. every event), you would want some things shown once at the top? (E.g. There were 16 events marked as "rock" genre.)

You can pass the total number of events to your custom shortcode as shortcode content, e.g.

[my-custom-shortcode][wpv-found-count][/my-custom-shortcode]

In the case of the rock genre statistic you would perform a query for events with the rock genre custom field (using get_posts), and could then perform your calculation with the results from that and the passed value of the View found results and return the required string.

For anything that you want to output for each iteration of the View loop, note that the current event post is available via the global $post object.

Learn more about custom shortcodes here: https://developer.wordpress.org/plugins/shortcodes/

And see https://developer.wordpress.org/reference/functions/get_posts/

#2274877

Hi Nigel,
thanks for your response.
But you don't necessarily want to display these things for every iteration (i.e. every event), you would want some things shown once at the top? (E.g. There were 16 events marked as "rock" genre.)
Yes, that is exactly what I am trying to do as well

In the case of the rock genre statistic you would perform a query for events with the rock genre custom field (using get_posts)
OK, so I need to find a way in PHP, right? Any hint, please? I am not familiar with PHP (that's why I use Toolset 🙂 🙂 )

Thanks very much,
Tom

#2275139

Nigel
Supporter

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

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

Sorry Tom, Toolset doesn't have the features you are looking for. I can't code new features for you. (I would suggest you submit a feature request, but in this case they are quite specific to your site and not so much a general purpose feature.)

If you are unfamiliar with PHP this is one time you'll need to involve a developer, I'm afraid.

#2278245

OK, I have managed to solve the problem with JQuery. Thanks anyway for the effort 🙂