I got the following code in my theme functions.php
I want to use it one more than one View so I think I need to change the code to something with array right? Not sure how to do it though.
function my_filter_query($query, $view_settings, $view_id) {
if($view_settings['view_id'] != 74955){ //if it is specific view
return $query;
}
$mm = date("m-Y", time()); // current month by default
if(isset($_REQUEST["mm"])){ // if it is pagination URL
$mm = $_REQUEST["mm"];
}
if(!empty($mm)) {
if (is_array($query['meta_query'])) {
foreach($query['meta_query'] as $i => $meta_query) {
//print_r($meta_query);
if (isset($meta_query['key']) && $meta_query['key'] == 'wpcf-program-tidspunkt') {
$start = strtotime("1-{$mm} 00:00:00");
$numdays = date("t", $start);
$end = strtotime("$numdays-{$mm} 23:59:59");
$meta_query['value'] = "$start,$end";
$meta_query['compare'] = 'BETWEEN';
$query['meta_query'][$i] = $meta_query;
}
}
}
}
return $query;
}
add_filter('wpv_filter_query', 'my_filter_query', 12, 3);
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Bob,
Thank you for getting in touch.
You can actually do this. Change your if statement to the one below.
if(NOT(in_array($view_settings['view_id'], array(1235,6789,10112)))){ //if it is specific view
return $query;
}
What you need to do is to add your view ids inside the array that you want the code to target.
Please let me know if this helps.
Thanks
Shane
My issue is resolved now. Thank you!