I am using this code in a Fields and Text block
<strong>No Shortcode - wprss_item_date:</strong> [acur_date_from_time time=1623762049]<br>
<strong>With Shortcode - wprss_item_date:</strong> [acur_date_from_time time='[types field="wprss_item_date"][/types]']<br>
<strong>RAW - wprss_item_date:</strong> [types field='wprss_item_date'][/types]<br>
My shortcode [acur_from_time] outputs a date when given a time in seconds.
The first line is to show that it works correctly
The second line is how I want to use it, with the time coming from a custom field.
The third line is to show that the custom field does contain a sensible value.
This image shows what appears within the block editor: it seems to be OK.
hidden link
This image shows what appears on the front end: the [types] shortcode isn't being recognised.
hidden link
(This is the key faulty output:
With Shortcode – wprss_item_date: 01 Jan 1970[/types]]
)
I've used this construct before and have run out of ideas of what to test...
Thanks
Alex
Hi Alex,
Thank you for contacting us and I'd be happy to assist.
Can you please make sure that the custom shortcode "acur_date_from_time" has been added in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content?
Also, since you need a raw date type custom field value, you can also replace "types" shortcode with the simpler "wpv-post-field" shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field
( note that for custom fields added by Types, you'll need to include the prefix "wpcf-" before the field slug )
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks Waqar
I'd tried registering the shortcode as a third-party argument, even though it wasn't being used to provide an argument. I registered it again anyway just now. I also tried using wpv-post-field instead of the types shortcode. All with no effect.
This is what I get
hidden link
(The field wprss-item-date is provided by another plugin, but I've set it to be "Managed with Types" in the Post Field Control section)
And just now, I deactivated all plugins except Toolset Types, Toolset Blocks and the WP RSS Aggregator plugins - still with no impact (and I cleared caching as well!)
Alex
Thanks for the update.
Can you please share temporary admin login details along with the link to the page where I can see these shortcodes?
I'd also like to see the code for the custom shortcode "acur_date_from_time".
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
Thank you for waiting and I apologize for the delay in getting back on this.
During testing on your staging website, I noticed that the issue is only happening when used inside a reusable block. The same nested shortcode works correctly, if it is directly added to the content template, without a reusable block.
Based on this the following updated code for the custom shortcode, works on my test website, even from inside a reusable block:
function acur_date_from_time_func( $atts, $content = null ) {
$content = do_shortcode($content);
if(!empty($content)) {
$postDate = date('d M Y', intval($content));
return $postDate;
}
}
add_shortcode( 'acur_date_from_time', 'acur_date_from_time_func' );
To use it, you'll need to provide the number or source shortcode as a shortcode's content instead of an attribute, for example:
[acur_date_from_time][wpv-post-field name="wprss_item_date"][/acur_date_from_time]
This should do the trick.
Perfect!
Thanks very much, Waqar.
My issue is resolved now.