Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Utility functions
- */
- function is_element_empty($element) {
- $element = trim($element);
- return !empty($element);
- }
- // Tell WordPress to use searchform.php from the templates/ directory
- function roots_get_search_form($form) {
- $form = '';
- locate_template('/templates/searchform.php', true, false);
- return $form;
- }
- add_filter('get_search_form', 'roots_get_search_form');
- //CONTENT HELPERS
- function get_calendar_page($params = array()) {
- $params = (!empty($params) ? $params : (!empty($_POST) ? $_POST : array()));
- $month = ( !empty($params['month']) ? $params['month'] : date('m') );
- $year = ( !empty($params['year']) ? $params['year'] : date('Y') );
- ob_start();
- include(locate_template('/templates/snippets/events-calendar.php'));
- $html = ob_get_contents();
- ob_end_clean();
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
- die(json_encode($html));
- } else {
- echo $html;
- }
- return;
- }
- add_action("wp_ajax_nopriv_get_calendar_page", "get_calendar_page");
- add_action("wp_ajax_get_calendar_page", "get_calendar_page");
- function get_events($params = array()) {
- $params = (!empty($params) ? $params : (!empty($_POST) ? $_POST : array()));
- if(!empty($params['paged'])) $custom_args['paged'] = $params['paged'];
- if(!empty($params['posts_per_page'])) $custom_args['posts_per_page'] = $params['posts_per_page'];
- $meta_query = array('relation' => 'AND');
- $tax_query = array('relation' => 'AND');
- if(!empty($params['tax'])):
- foreach ($params['tax'] as $tax_key => $tax):
- if(!empty($tax) && $tax && $tax != "null"):
- if(!is_array($tax)) $tax = array( $tax );
- $tax_query[] = array(
- 'taxonomy' => $tax_key,
- 'field' => 'term_id',
- 'terms' => $tax,
- );
- endif;
- endforeach;
- endif;
- if( !empty($params['date']) && $params['date'] && $params['date'] != "null"):
- $date_start = strtotime( date('d-m-Y', $params['date']) );
- $date_end = strtotime( date('d-m-Y', $params['date']) . ' + 1day' );
- $meta_query[] = array(
- array(
- "key" => "event_start_time",
- "compare" => "BETWEEN",
- "value" => array( $date_start, $date_end ),
- )
- );
- endif;
- $default_args = array(
- 'post_type' => 'event',
- "orderby" => "event_start_time",
- "order" => "ASC",
- "posts_per_page" => -1,
- "paged" => 1,
- 'tax_query' => $tax_query,
- 'meta_query' => $meta_query,
- );
- $args = array_merge( $default_args, $custom_args );
- $query = new WP_Query( $args );
- ob_start();
- /* ?><div class="result-item grid-item col-sm-12"><pre><?php
- print_r($query->request);
- ?></pre></div><?php */
- if ( $query->have_posts() ): ?>
- <?php while ( $query->have_posts() ): $query->the_post(); ?>
- <?php get_template_part('templates/snippets/event-item'); ?>
- <?php endwhile; ?>
- <?php endif;
- $html = ob_get_contents();
- ob_end_clean();
- wp_reset_query();
- $return = array(
- 'found_posts' => $query->found_posts,
- 'max_num_pages' => $query->max_num_pages,
- 'query_id' => $_POST['query_id'],
- 'html' => $html,
- 'mq' => $meta_query,
- );
- if(!empty($_POST['query_id'])):
- die(json_encode($return));
- else:
- return $return;
- endif;
- }
- add_action("wp_ajax_nopriv_get_events", "get_events");
- add_action("wp_ajax_get_events", "get_events");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement