Hello,
I have implemented a snippet suggested in one of your support threads (I can't find the link anymore, I cleared my cache recently, sorry!) that works fine. I just have simplified the output to get 0 or 1 if one date is <= another date.
I have a test page called "aaa" where the shortcode returns correct results. But when I use the same shortcode in the content template I am creating it returns strange results.
I have a conditional block to test the function output for: "if function output=0 write something, if function output= 1 write something else" (see picture). The conditional fails so I have displayed the shortcode output in a paragraph to visualize the shortcode output and it always returns 0"] (0 + last 2 characters of the shortcode). The shortcode is
[show_day_difference date="[types field='application-date' output='raw'][/types]"]
exactly the same of the "aaa" page, just copied, so it should return the same output, but it doesn't. Any clue ?
Thanks
Regards
Nicola
Hi Shane,
thanks for replying. I added the same shortcode to a Fields and text block but as you can see the result is exactly the same. Most importantly, the conditional fails and it fails also if I replace
The result of [dates-difference date=[types field='application-date' output='raw']] is equal to 1
with
The result of [dates-difference date=[types field='application-date' output='raw']] is equal to 0"]
Can it be a shortcode bug ?
thanks
This isn't a shortcode bug. The problem is wordpress core itself removed support for nesting of shortcodes. However this should work when used in our Content Template.
There is a way you can workaround this by only including the custom field slug as the parameter and then retrieve the custom field value inside your shortcode using the function below.
Hi Shane
following your suggestion I changed the shortcode into this:
[show_day_difference date="types_render_field("application-date", array("style" => "calendar"))"]
and now it returns 0 instead of 0"]. Issue is that it ALWAYS returns 0 even when the function on the test page returns 1.
I suppose that this 0 isn't the one returned by the function but some kind of error message ... don't know ....
I tried also to change the quotation marks like this, no change
[show_day_difference date="types_render_field('application-date', array('style' => 'calendar'))"]
Any clue ?
This is not what i'm suggesting. I'm assuming here that the show_date_difference is a shortcode that you've created.
In such a case then you can modify the shortcode to use the types_render_field() function inside the function for the shortcode.
So what you will be passing into the shortcode is the slug of the custom field. Can you send me the function for your custom shortcode so that I can make the modifications.
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_shortcode("show_day_difference", "show_day_difference_func");
function show_day_difference_func($atts) {
$a = shortcode_atts( array(
'date' => ''
), $atts );
// today's date
$current_date = date( 'U' );
// date to compare
$compare_date = $a['date'];
// difference in dates
$datediff = $compare_date - $current_date;
// difference in number of days
$datediffdays = round($datediff / (60 * 60 * 24));
// conditional display of difference based on number of days
if( ($datediffdays >= 0)) {
$output = '1';
}
elseif ($datediffdays < 0) {
$output = '0';
}
return $output;
}
Hi Shane
I apologise to bother you again on this, but the function now works and the correct output is displayed on the page. Although the conditional fails. It is a very simple conditional:
( ( '[date-lag date='application-date']' eq '1' ) ) ... or eq '0', one of the two...
It drives me mad why such a simple test doesn't work ! Any clue?
thanks
Regards
Nicola
Hi Shane
debug IS on already (see picture) but nothing is displayed in frontend ....
Same with this
( ( '[date-lag date='application-date' debug='true']' ne '0' ) )