Skip Navigation

[Resuelto] condition combine dont work

This support ticket is created hace 3 años, 4 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 39 respuestas, tiene 2 mensajes.

Última actualización por alexd-6 hace 3 años, 4 meses.

Asistido por: Minesh.

Autor
Mensajes
#2110041

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I checked and I found that the following view basically returns 1 result:
=> enlace oculto

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'

#2110057

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?

#2110059

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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:
=> enlace oculto

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.

#2110067

hey,

but if i give "ne" to filter - it works not, too:

[wpv-conditional if="( '[datetime]' ne 'aktiv') AND ( $(wpcf-highlight) eq '1' )" ]
#2110069

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I just change the condition to ne and I can see its working: enlace oculto
=> enlace oculto

 [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.
=> enlace oculto

#2110079

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?

#2110087

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.
=> enlace oculto

#2110089

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..

#2110095

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2110097

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?

#2110105

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2110149

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

#2110167

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" - enlace oculto

But at end of Slider it comes empty - how switch this to first? - you know what i mean?
enlace oculto

best regards and thx for all.. - alex

#2110305

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2110773

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