Skip Navigation

[Closed] I have a code snippet that causes a WordPress error 503 (Varnish Cache server)

This support ticket is created 2 years, 2 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2483265

I have a PHP code snippet that I have copied here in the FAQ (and I also opened a ticket for it 7 months ago).

This code is used to create a Date filter (less than a week, less than a month, etc.). It worked for a time and now it seems to create a bug .... (to help you understand I can tell you that the host uses PHP 8.1)

You can experience it here : hidden link (choose something in the date dropdown menu)
Here is the code :
<?php
/**
* Ce code permet d'interpréter le filtre par date pour le calendrier interactif
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_filter( 'wpv_filter_query', 'func_custom_filter_query', 10, 3);
function func_custom_filter_query( $view_args, $view_settings, $view_id ){

if ( 38883 == $view_id ) {

if ( (isset($view_args['meta_query'])) && (!empty($view_args['meta_query'])) ) {

$target_field = "wpcf-date-debut"; // change this field slug to your field slug

foreach ($view_args['meta_query'] as $key => $value):
if ($value['key'] == $target_field){

$option = $value['value'];
$start = time();
if($option==1){
$end = strtotime("+7 day",$start);
}else if($option==2){
$end = strtotime("+1 month",$start);
}else if($option==3){
$end = strtotime("+3 month",$start);
}else if($option==4){
$end = strtotime("+6 month",$start);
}else if($option==5){
$end = strtotime("+12 month",$start);
}else if($option==0){
unset($view_args['meta_query'][$key]);
return $view_args;

}

$filer_index = $key;

}
endforeach;

if ( isset($filer_index) ) {

$view_args['meta_query'][$filer_index] = array('key' => $target_field,
'value' => array($start, $end),
'type' => 'NUMERIC',
'compare' => 'BETWEEN' );
}

}

}

return $view_args;
}

thank you !!

#2483699

Hi,

Thank you for contacting us and I'd be happy to assist.

Have you checked the server's error logs to see if any errors or warnings are logged in there? If not, I'll recommend temporarily enabling WordPress debugging and checking the server's error log, after using the date filter.
( ref: https://wordpress.org/support/article/debugging-in-wordpress/ )

Please also test if switching to PHP 7 has any effect on this so that it can be narrowed down, accordingly.

I hope this helps and let me know how it goes.

regards,
Waqar

The topic ‘[Closed] I have a code snippet that causes a WordPress error 503 (Varnish Cache server)’ is closed to new replies.