Skip Navigation

[Gelöst] Issues Using a shortcode with embedded shortcode in Conditional Output

This support ticket is created vor 4 Jahre, 11 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by Chris vor 4 Jahre, 11 Monate.

Assisted by: Luo Yang.

Author
Artikel
#1241227

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?

#1241327

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

#1241931

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

#1241974

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/

#1243746
Annotation 2019-05-14 130901.jpg

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.

#1243788

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

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