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.
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.
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.
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!
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!
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.
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.
New threads created by Minesh and linked to this one are listed below: