HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/hcv/wp-content/themes/hockey/pages/free-drills.php
<?php
/*
 * Template Name: Free Drills
 *
 */

$context = Timber::context();
$context['reset_url'] = strtok($_SERVER['REQUEST_URI'], '?');

if(empty($_GET["age"])){
    $filter_age = null;
}else{
    $filter_age = $_GET["age"];
}
$context['filter_age'] = $filter_age;

$ages = get_terms([
    'taxonomy' => 'free_drill_age',
    'hide_empty' => true,
]);
foreach ($ages as $age){
    if($filter_age){
        $age->checked = in_array((string)$age->slug, explode(',', $filter_age));
    }else{
        $age->checked = false;
    }
}
$context['ages'] = $ages;

if(empty($_GET["cat"])){
    $filter_cat = null;
}else{
    $filter_cat = $_GET["cat"];
}
$context['filter_cat'] = $filter_cat;

$categories = get_terms([
    'taxonomy' => 'free_drill_categories',
    'hide_empty' => true
]);
foreach ($categories as $cat){
    if($filter_cat){
        $cat->checked = in_array((string)$cat->slug, explode(',', $filter_cat));
    }else{
        $cat->checked = false;
    }
}
$context['categories'] = $categories;
$tax_query = [];
if($filter_age){
    array_push($tax_query, array(
        'taxonomy' => 'free_drill_age',
        'field'    => 'slug',
        'terms'    => explode(',', $filter_age),
    ));
}
if($filter_cat){
    array_push($tax_query, array(
        'taxonomy' => 'free_drill_categories',
        'field'    => 'slug',
        'terms'    => explode(',', $filter_cat),
        'operator' => 'AND',
    ));
}

global $paged;
if (!isset($paged) || !$paged){
    $paged = 1;
}

$args = array(
    'numberposts' => 9,
    'post_type' => 'free_drill',
    'paged' => $paged
);

if(count($tax_query) > 0){
    $tax_query['relation'] = 'AND';
    $args['tax_query'] = $tax_query;
}
$drills = new Timber\PostQuery($args);

foreach ($drills as $drill){
    //Compare dates
    $post_date  = strtotime($drill->post_date);
    $two_weeks_ago =   strtotime("-14 days");

    $drill->is_new = $post_date > $two_weeks_ago;
}

$context['posts'] = $drills;

$context['pagination'] = $context['posts']->pagination(10000);

Timber::render( array( 'pages/free-drills.twig', 'page.twig' ), $context );