Skip Navigation

[Resolved] Sum data stored in custom fields

This support ticket is created 4 years, 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Kelly 4 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1727335

Hi, I suspect I just haven't read the right bit of documentation for this.

I have some related posts types. In this example, I'm looking at a Microcycle, which contains beneath it multiple Sessions.

Each session has a field called "distance". I want to, when looking at the Microcycle, sum up the distances for each session and display a total for them.

Looking at views, I can't see an immediate way to do this, but https://toolset.com/documentation/programmer-reference/displaying-custom-functions-with-views-and-using-them-in-conditional-logic/ seems to suggest I can create a custom shortcode and use that?

I imagine that in the content template for the Microcycle include a view which requests all the related sessions and in that view place the shortcode. That custom code in the shortcode would then iterate over the loop of session posts, sum up the field and output the total.

However, I can't work out how I would add a short code into a view! I can't find documentation explaining this bit? The link above talks about writing the code, but not how to actually display it anywhere? 🙂

I copied the example function from the documentation, added it into the Custom code snippets section and tested it (no errors) and added the shortcode to the view. The view then just outputs the text of the shortcode, not actually executing it. Putting that shortcode into the content template also just outputs the shortcode name as well.

Am I being dumb? 🙂

#1727787

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Here is the Doc that explains how you can create custom shortcode and use it:
=> https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/#using-the-custom-shortcode

If you still require further assistance with your issue, I would be happy to help but to help you further I will require problem URL where you want to display the total and for which field with access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1728333
screenshot4.gif
screenshot3.gif
screenshot2.gif
screenshot1.gif

Hi, I've read that documentation but I'm still not clear how to use a shortcode in a view.

I've defined a shortcode in Settings->Custom Code. (Screenshot 1). It's just the example from the documentation, nothing special
I've added it in Third-party shortcode arguments (even though I don't think this is right, as right now I'm just wanting to output text as a test) (screenshot 2)
I've added the shortcode into a view (screenshot 3)

The text of the shortcode just outputs in the view however, rather than "executing" it. (screenshot 4). I'm blatantly just doing something stupid though!

#1728369

I'm an idiot! I hadn't "activated" the custom code snippet!

I've now got the code working. I've not closed this just in case I need a hand to work out how to access the data in the code section 🙂

If that goes fine, i'll close it 🙂

#1728533

Hi! I've now got this working.

One last question, sometimes if I mess up and call the functions but missing a required argument for example, the page crashes without any error output in the logs or the screen. Is this by design? It would be handy to see them!

#1728931

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I do not see you are passing any argument to your shortcode and to know if your shortcode is causing the issue you need to add error_log() with your desired text string within your shortcode.

For example:

error_log( 'Hello World!' );

More info:
=> https://stackoverflow.com/questions/24330039/how-can-i-use-error-log-with-wordpress

#1729121

I'm referring to an argument in the code. I.e. i had misread toolset_get_related_posts and was only passing 2 arguments instead of the three I needed. This code however would pass in the test in the settings, but cause the whole toolset application to crash without outputting any errors.

I'd expect to see some errors logged via the default wordpress error reporting.

#1729173

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thats another issue. I need to test it and check how exactly you are using the toolset_get_related_posts() that broke your site.

You can close this ticket and I will split the ticket and there you can share all required information that should help me to reproduce the issue.

#1730437

My issue is resolved now. Thank you!