mage-eventpress/inc/mep_query.php

104 lines
3.8 KiB
PHP

<?php
function mep_event_query($type,$show,$sort='',$cat='',$org='',$evnt_type = 'upcoming'){
$event_expire_on = mep_get_option( 'mep_event_expire_on_datetimes', 'general_setting_sec', 'event_start_datetime');
$now = current_time('Y-m-d H:i:s');
$paged = get_query_var("paged") ? get_query_var("paged") : 1;
$etype = $evnt_type == 'expired' ? '<' : '>';
if($type='all'){
$args = array(
'post_type' => array('mep_events'),
'paged' => $paged,
'posts_per_page' => $show,
'order' => $sort,
'orderby' => 'meta_value',
'meta_key' => 'event_start_datetime',
'meta_query' => array(
array(
'key' => $event_expire_on,
'value' => $now,
'compare' => $etype
)
)
);
$loop = new WP_Query($args);
}elseif($type == 'cat'){
$args = array(
'post_type' => array('mep_events'),
'paged' => $paged,
'posts_per_page' => $show,
'order' => $sort,
'orderby' => 'meta_value',
'meta_key' => 'event_start_datetime',
'meta_query' => array(
array(
'key' => $event_expire_on,
'value' => $now,
'compare' => $etype
)
),
'tax_query' => array(
array(
'taxonomy' => 'mep_cat',
'field' => 'term_id',
'terms' => $cat
)
)
);
$loop = new WP_Query($args);
}elseif($type == 'org'){
$args = array(
'post_type' => array('mep_events'),
'posts_per_page' => $show,
'paged' => $paged,
'order' => $sort,
'orderby' => 'meta_value',
'meta_key' => 'event_start_datetime',
'meta_query' => array(
array(
'key' => $event_expire_on,
'value' => $now,
'compare' => $etype
)
),
'tax_query' => array(
array(
'taxonomy' => 'mep_org',
'field' => 'term_id',
'terms' => $org
)
)
);
$loop = new WP_Query($args);
}
return $loop;
}
function mep_event_pagination($total_page){
$paged = get_query_var("paged") ? get_query_var("paged") : 1;
?>
<div class="row">
<div class="col-md-12"><?php
$pargs = array(
"current" => $paged,
"total" => $total_page
);
echo "<div class='pagination-sec'>" . paginate_links($pargs) . "</div>";
?>
</div>
</div>
<?php
}