Skip Navigation

[Resolved] Shortcode not working consistently across all views

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.

This topic contains 5 replies, has 2 voices.

Last updated by MattI4840 1 year, 1 month ago.

Assigned support staff: Christian Cox.


I am trying to:

I created a shortcode that formats numbers to only display two decimal places. This works fine in several views, but the latest view I created uses a collapsible containers, and the number field I want to use the shortcode with is displayed within the title of the collapsible container. It appears this is restricting the shortcode from working properly.

Here is the code for the shortcode:

function yls_format_tons( $atts, $content ) {
    $content = do_shortcode($content);
    return $value = number_format((float)$content, 2);
add_shortcode('format_tons', 'yls_format_tons');

This is the loop editor code for the view where the short code is used:

	<!-- wpv-loop-start -->
<div class="list-group">
	[su_accordion]<ul class="wpv-loop js-wpv-loop">
          <li class="list-group-item">
          [su_spoiler title="[wpv-post-title] &nbsp;&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp; Total Tons: [types field='tons-tbd'][/types] &nbsp;&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp; Tons Left: [types field='tons-ltbd'][/types]" open="no" style="" icon="" anchor="" class=""][wpv-view name="related-contracts"][/su_spoiler]</li>
	<!-- wpv-loop-end -->
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>

And the code for the templates section:

[format_tons][types field='tons-tbd'][/types][/format_tons]
[format_tons][types field='tons-ltbd'][/types][/format_tons]

As you can see from the screenshot, the shortcode is not working. I've also tried placing it in the loop editor section and that causes the title section to go back to the default (+spoiler) text. Any help would be greatly appreciated.


Christian Cox

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

As you can see from the screenshot, the shortcode is not working.
I can't really see that in the screenshot, sorry. I can see the su_spoiler title, which is set by this code:

[wpv-post-title] &nbsp;&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp; Total Tons: [types field='tons-tbd'][/types] &nbsp;&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp; Tons Left: [types field='tons-ltbd'][/types]

From what I can tell, this is what sets the text in the title of each of the 3 CON002 items shown in the middle of the output. I can see that these numbers are not formatted, true, but the shortcode isn't used here so I wouldn't expect the numbers to be formatted to only 2 decimal places.

Then you mentioned this code in the View's template:

[format_tons][types field='tons-tbd'][/types][/format_tons]
[format_tons][types field='tons-ltbd'][/types][/format_tons]

I don't see that information displayed anywhere in the View results. Even if there was a problem with format_tons, the wpv-post-title should appear as expected here, so something else is going on. Is it possible there is some CSS hiding the results of the nested View "related-contracts"? Can I see this in the browser?



Apologies, you are correct you can't see it in that screenshot. I had previously had the shortcode in the spoiler text which was not working, I removed it before sending this to you. I am working on this locally, but I can send you a duplicator pro package, I just don't see the secure attachment interface in the ticket right now.



Christian Cox

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Sure, I'll activate those fields here.


Christian Cox

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

We're talking about the Open Contracts, page, correct? Try registering format_tons in Toolset > Settings > Front-end Content > Third-party Shortcode Attributes. After that, I was able to use it in the su_spoiler title attribute.


That's very odd, I've now also registered it as a 3rd party short code and it still is not working. This is low priority at the moment though, you can close this and I'll revisit if I can't get it working later.