I'm having an issue when trying to use a shortcode with embedded shortcode in Conditional Output, here's the code
[wpv-conditional if="( $(wpcf-price) ne '0' )"]
<div class="price">$ [format-currency num="[types field='price' output='raw'][/types]"]</div>
[/wpv-conditional]
when I use it outside of the conditional it works flawlessly but when I use it within the contidional it outputs this at the front end
$ [format-currency num="27447.00"]
the code for the format-currency shortcode function in the functions.php file is
function format_my_number($atts) {
$num = $atts["num"];
return number_format($num, 0, '.', ',');
}add_shortcode("format-currency", "format_my_number");
Link to a page where the issue can be seen:
hidden link
Could you help me with this issue please?
Hello,
I have tried your codes in my localhost with a fresh wordpress installation + the latest version of Toolset plugins, there isn't similar problem, and I see another problem:PHP errors when the custom field "Price" is empty:
Warning: number_format() expects parameter 1 to be float,
I suggest you check these:
1) Change the PHP codes as below:
function format_my_number($atts) {
$atts = shortcode_atts( array(
'num' => 0,
), $atts);
$num = $atts["num"];
if(is_numeric($num)){
return number_format($num, 0, '.', ',');
}
}add_shortcode("format-currency", "format_my_number");
This will avoid the PHP errors when price value is empty.
2) Dashboard-> Toolset-> Settings-> Front-end Content
in section "Third-party shortcode arguments", add your custom shortcode name: format-currency
3) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/
4) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2019, deactivate all other custom PHP snippets, and test again
I did all the recomendations but unfortunately it stills not working, funny thing is that i use the exact same code on a view and it works just fine
hidden link
but in a template it just doesn't
hidden link
There isn't similar problem in my localhost with a fresh wordpress installation + the latest version of Toolset plugins.
Please try as I mentioned above:
1) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2019, deactivate all other custom PHP snippets, and test again
2) If the problem still persists, please provide database dump file(ZIP file) of your website, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/
I'm sorry but I've tried all of the above and still not working, unfortunately I also can't send you a dump of my site this error keeps showing, I still need help.
Ok I found a work around but I still thinking that there is a bug somewhere, the problem was fixed when I deleted this code that where somewhere below my template
[wpv-conditional if="( $(wpcf-gallery) ne '' )"]
<div class="customGallery">
<div class="container mainContainer">
<div class="row">
[wpv-for-each field="wpcf-gallery"]
<div class="col-sm-4">
<div class="galleryItem">
<a class="prettyphoto" href="[types field='gallery' size='full' url='true' resize='proportional'][/types]" rel="prettyPhoto[portfolio]">
<div style="background-image: url('[types field='gallery' size='medium-large' url='true' resize='proportional'][/types]');" class="image"><div class="imgCaption"></div></div>
</a>
</div>
</div>
[/wpv-for-each]
</div> <!--.row-->
</div><!--.mainContainer-->
</div><!--/.customGallery-->
[/wpv-conditional]
Specifically it has a problem with the a tag, so my work around far from ideal was to remove the this conditional tag from my code
[wpv-conditional if="( $(wpcf-gallery) ne '' )"].... [/wpv-conditional]
hopefully this could help someone