I have a custom date field in UNIX timestamp format, called offer_expire. It perfectly returns its content but as UNIX timestamp string :
[wpv-post-field name="offer_expire"] -----> 1593129600
I've tried to use the PHP Date function as cycle element like this
<p>Offer expire date: </p><?php echo(date("d-m-Y",[wpv-post-field name="offer_expire"]));?>
and also
<p>Offer expire date: </p>
<?php echo(date("d-m-Y",[wpv-post-field name="offer_expire"]));?>
but nothing is displayed in both cases
Anything wrong in the syntax ? or can you suggest a better method ? Please help.
Thanks
If this is in a PHP template, you cannot just call a ShortCode and expect it to work.
You'd need to "expand" that ShortCode, with do_shortcode() or wpv_do_shortcode().
do_shortcode() is a WordPress native function explained here and wpv_do_shortcode is just a copy of it, however, it passes the shortcode thru Toolset's expander and should show fewer issues with nested ShortCodes.
https://developer.wordpress.org/reference/functions/do_shortcode/
Or, you can simply use Toolset's Fields API to render the field and/or get its value, in the code:
https://toolset.com/documentation/customizing-sites-using-php/functions/
Note, depending on the type of field used you'll want "raw" values, hence, in that case, you'll have to pass the output attribute, see an example:
https://toolset.com/documentation/customizing-sites-using-php/functions/#textfield
If that is not a Toolset field, you would rather use get_post_meta():
https://developer.wordpress.org/reference/functions/get_post_meta/
Thank you Boda and Nigel (his reply I cannot see here, but I received his email).
Unfortunately I am not a PHP programmer so even though I understand what you say in principles I am not really in the conditions to execute it. I might find somebody who can. For I am using a third party's theme that I've bought and I can see that all data I need is shown on their pages it means that somewhere they have developed functions that retrieve it and make all necessay conversions. If so, is there any tutorial that explains how to use existing functions in Toolset ?
Yes, me and Nigel crossed replies here, I see he deleted his, however it was just as valid as my reply 🙂
There is no tutorial as you describe, I fear, however you might be able to find help at the https://toolset.com/contractors/ list, or, you can use our Forum to find solutions, also we have a (limited) library of custom code at hidden link which can be good for inspiration, or Pastebin accounts like these https://pastebin.com/u/bedas 😉
However, you just need to use either WordPress API or Toolset API for this, it's barely more than copy-paste and edit from these examples to a new custom code:
https://toolset.com/documentation/customizing-sites-using-php/functions/
For example,
<?php echo(date("d-m-Y",types_render_field( "the-field-slug-where-date-is-stored", array("output" => "raw" ) )));?>
This should output the date() formate set using the timestamp from your date field.
But in fact, you can also just output the actual Toolset Date Field as ShortCode already using Timestamp output or any custom output you want, when you use the Toolset Field ShortCode to display date fields.
If you use a custom (other) field than date field, you logically will need to apply the custom function you show above, with the proper data as I show in the example.
My issue is resolved now. Thank you!