Home / Admin / 0000 > CLASS > Show Data
Duplicate Snippet

Embed Snippet on Your Site

0000 > CLASS > Show Data

Code Preview
php
<?php
// this is the class definition
class myfair_Show_Data
{
    public function __construct()
    {
        $this->loadShows();
        if (isset($this->showList) && is_array($this->showList) && count($this->showList) > 0) {
            $this->loadShowCustomData();
        }
    }
    public function loadShows()
    {
        $loop = new WP_Query(array(
            'post_type' => 'show',
            'post_parent' => '0',
            'posts_per_page' => '-1',
            'meta_key' => 'end_date',
            'orderby' => 'meta_value',
            'order' => 'ASC'
        ));
        if ($loop->have_posts()) {
            $this->showList = $loop->posts;
        }
        wp_reset_postdata();
    }
    // getter function  // factory method?
    public function getShowList()
    {
        return $this->showList;
    }
    public function loadShowCustomData()
    {
        $shows = $this->getShowList();
        $data = [];
        $today = date('Ymd');
        if (!empty($shows)) {
            $data['count'] = count($shows);
            foreach ($shows as $show) {
                $s_id = $show->ID;
                $city = get_post_meta($s_id, 'city', true);
                $data['all'][$city][] = $s_id;
					
                if (function_exists('get_field') && get_field('start_date', $s_id) >= $today) {
                    $data['future']['all'][] = $s_id;
                    $data['future'][$city][] = $s_id;
                } else {
                    $data['past']['all'][] = $s_id;
                    $data['past'][$city][] = $s_id;
                }
            }
        }
        $this->customData = $data;
    }
    // getter function  // factory method?
    public function getCustomData()
    {
        return $this->customData;
    }
}

Comments

Add a Comment