Skip Navigation

[Resolved] Function code change to array

This support ticket is created 4 years, 1 month 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by bobA-2 4 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1826967

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);

#1827413

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

#1827623

My issue is resolved now. Thank you!