Home › Toolset Professional Support › [Resolved] condition combine dont work
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
Related documentation:
This topic contains 39 replies, has 2 voices.
Last updated by alexd-6 3 years, 3 months ago.
Assisted by: Minesh.
I checked and I found that the following view basically returns 1 result:
=> hidden link
But then if we add the condition:
[wpv-conditional if="( '[datetime postidmy='[wpv-post-id]']' eq 'aktiv') AND ( $(wpcf-highlight) eq '1' )" ]
As the date time shortcode does NOT return the 'aktiv' - there is nothing to display. That is why you can not see anything. How exactly you would like to display the result and what is the role of condition here with 'aktiv' and 'inaktiv'
Hi,
we dont need the [datetime postidmy='[wpv-post-id]']
in Shortcode is set Post ID automatically:
$post_id = $Post->ID;
that means this is right one
[wpv-conditional if="( '[datetime]' eq 'aktiv') AND ( $(wpcf-highlight) eq '1' )" ]
And: i dont see shortcode function in function.php.. - did you remove it?
I've adjusted the code so we can use the - that provides more readability to the code and its working, so we can go with the following code:
[wpv-conditional if="( '[datetime postidmy='[wpv-post-id]']' eq 'aktiv') AND ( $(wpcf-highlight) eq '1' )" ]
You should forget about that as it is working fine.
What I'm asking is:
I checked and I found that the following view basically returns ONLY 1 result:
=> hidden link
And with the above condition, as condition becomes false there is not records available to display as there is only 1 record and that record is not displayed because above condition is not satisfied.
hey,
but if i give "ne" to filter - it works not, too:
[wpv-conditional if="( '[datetime]' ne 'aktiv') AND ( $(wpcf-highlight) eq '1' )" ]
I just change the condition to ne and I can see its working: hidden link
=> hidden link
[wpv-conditional if="( '[datetime postidmy='[wpv-post-id]']' ne 'aktiv') AND ( $(wpcf-highlight) eq '1' )" ]
The [datetime] shortcode is moved to "Custom Code" section offered by Toolset.
=> hidden link
hey - the function was original:
function myownfunc( $atts ) { // $post_id = $atts['postidmy']; $post_id = $Post->ID; $fieldvalues = toolset_get_related_posts( get_the_ID(), "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object')); $today = date("j. F Y H:i"); $todaytimestamp = strtotime($today); $temp = array(); foreach ($fieldvalues as $fieldvalue) { $partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID)); $partone = $partone; $temp[] = strtotime($partone); //$temp2[] = $partone; foreach ($temp as &$value) { // $value = $value * 2; if ($value < $todaytimestamp) { $statusinaktiv = 'inaktiv'; }else{ $statusaktiv = 'aktiv'; } } // print $status; } // return join(" - ",$temp). "<br>" .$todaytimestamp . "<br>" . $statusaktiv . "<br>" . $statusinaktiv; return $statusaktiv; } // [datetime postidmy="[wpv-post-id]"] add_shortcode( 'datetime', 'myownfunc' );
i changed the foreach for $statusaktiv.. - other var $statusinaktiv is not needed..
you know what i mean?
What I'm saying is that code you shared above is modified as given under and its working:
function myownfunc( $atts ) { $post_id = $atts['postidmy']; // $post_id = $Post->ID; $fieldvalues = toolset_get_related_posts( $post_id, "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object')); $today = date("j. F Y H:i"); $todaytimestamp = strtotime($today); $temp = array(); foreach ($fieldvalues as $fieldvalue) { $partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID)); $partone = $partone; $temp[] = strtotime($partone); //$temp2[] = $partone; foreach ($temp as &$value) { // $value = $value * 2; if ($value < $todaytimestamp) { $state = 'inaktiv'; }else{ $state = 'aktiv'; } } // print $status; } // return join(" - ",$temp). "<br>" .$todaytimestamp . "<br>" . $statusaktiv . "<br>" . $statusinaktiv; return $state; } // [datetime postidmy="[wpv-post-id]"] add_shortcode( 'datetime', 'myownfunc' );
The [datetime] shortcode is moved to "Custom Code" section offered by Toolset.
=> hidden link
hi,
yes 😉 - but i modified the code at
foreach ($temp as &$value) { // $value = $value * 2; if ($value < $todaytimestamp) { $statusinaktiv = 'inaktiv'; }else{ $statusaktiv = 'aktiv'; } } // print $status; } // return join(" - ",$temp). "<br>" .$todaytimestamp . "<br>" . $statusaktiv . "<br>" . $statusinaktiv; return $statusaktiv;
this gives "aktiv" in shortcode or nothing..
You should not modify the code as the shortcode should return at lease some value. That is why I modified the code as:
foreach ($temp as &$value) { // $value = $value * 2; if ($value < $todaytimestamp) { $state = 'inaktiv'; }else{ $state = 'aktiv'; } } // print $status; } // return join(" - ",$temp). "<br>" .$todaytimestamp . "<br>" . $statusaktiv . "<br>" . $statusinaktiv; return $state;
You should keep using it.
hey,
yes but you are toggle var $state -> i only give $statusaktiv a state if one of all values get "$statusaktiv = aktiv.
So i got aktiv is one value aktiv, this is what i want.
you know what i mean?
So , if you are looking that if there is even one future date available out of all the repeating field group items then you want to return the aktive otherwise inaktive then I've modified the code as given undeR:
$state = 'inaktiv'; foreach ($temp as &$value) { // $value = $value * 2; if ($value < $todaytimestamp) { $state = 'inaktiv'; }else{ $state = 'aktiv'; break; } }
Can you please confirm it works at your end as well.
Hey minesh - i dont see the last message of you here in forum:
But i aggree with your code:
$state = 'inaktiv'; foreach ($temp as &$value) { // $value = $value * 2; if ($value < $todaytimestamp) { $state = 'inaktiv'; }else{ $state = 'aktiv'; break; } }
do you addedt it again? - Now it works?
thx for all - alex
Hi Minesh.. - i dont know why, but now it worked.. - i gave 3 "Posts" a date in future and highlight checkbox.
These Post are "aktiv" - hidden link
But at end of Slider it comes empty - how switch this to first? - you know what i mean?
hidden link
best regards and thx for all.. - alex
I've adjusted the code added to "Custom Code" section as given under:
function myownfunc( $atts ) { $post_id = $atts['postidmy']; // $post_id = $Post->ID; $fieldvalues = toolset_get_related_posts( $post_id, "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object')); $today = date("j. F Y H:i"); $todaytimestamp = strtotime($today); $temp = array(); foreach ($fieldvalues as $fieldvalue) { $partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID)); // $partone = $partone; // $temp[] = strtotime($partone); $state = 'inaktiv'; //foreach ($temp as &$value) { // $value = $value * 2; //if ($value < $todaytimestamp) { if ($partone < $todaytimestamp) { $state = 'inaktiv'; }else{ $state = 'aktiv'; break; } // } // print $status; } // return join(" - ",$temp). "<br>" .$todaytimestamp . "<br>" . $statusaktiv . "<br>" . $statusinaktiv; return $state; } // [datetime postidmy="[wpv-post-id]"] add_shortcode( 'datetime', 'myownfunc' );
Can you confirm it works as expected.
Hi Minesh - i can confirm that.
But if i change state to
[wpv-conditional if="( '[datetime postidmy='[wpv-post-id]']' ne 'aktiv') AND ( $(wpcf-highlight) eq '1' )"]
and in foreach loop i move the break, to $state = inaktiv loop.
it dont work..
i dont understand it, for real.
thx - alex