Skip Navigation

[Resolved] Shortcode not working consistently across all views

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

Our next available supporter will start replying to tickets in about 2.19 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by MattI4840 4 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1300785
Capture.JPG

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-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<div class="list-group">
	[su_accordion]<ul class="wpv-loop js-wpv-loop">
		<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>
	</ul>[/su_accordion]
</div>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

And the code for the templates section:

[wpv-post-title]
[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.

#1300839

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:

[wpv-post-title]
[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?

#1302947

Christian,

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.

Thanks,
Matt

#1302973

Sure, I'll activate those fields here.

#1303151

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.

#1309615

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.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.