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] | Total Tons: [types field='tons-tbd'][/types] | 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.
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] | Total Tons: [types field='tons-tbd'][/types] | 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?
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
Sure, I'll activate those fields here.
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.