Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Template Name: Test template
- */
- get_header();
- // setting up currtime timestamp variable...
- $now = new DateTime();
- $currtime = $now->getTimestamp();
- /*
- * Setup query to show the 3 Event Posts in Slider.
- */
- $weekly_repeat_array = array( '1' => 'monday', '2' => 'tuesday', '3' => 'wednesday', '4' => 'thursday', '5' => 'friday', '6' => 'saturday', '7' => 'sunday' );
- $week_of_month_repeat = array( '1' => 'first', '2' => 'second', '3' => 'third', '4' => 'fourth', '5' => 'fifth', '6' => 'last' );
- $args = array(
- 'post_type' => 'ajde_events',
- 'posts_per_page' => -1,
- 'meta_query' => array(
- array(
- 'key' => 'evcal_erow',
- 'value' => $currtime,
- 'compare' => '>=',
- ),
- array(
- 'key' => '_featured',
- 'value' => 'no',
- ),
- ),
- 'post__not_in' => '',
- 'meta_key' => 'evcal_erow',
- 'orderby' => 'meta_value',
- 'order' => 'ASC',
- );
- $loop = new WP_Query( $args );
- $events_data = array();
- while ( $loop->have_posts() ): $loop->the_post();
- $do_not_duplicate[] = $post->ID;
- $event_startend_data = get_post_meta( get_the_ID() );
- // var_dump( $event_startend_data );
- if ( $event_startend_data ) {
- $event_original_start = $event_startend_data['evcal_srow'][0];
- $event_original_end = $event_startend_data['evcal_erow'][0];
- $event_link = get_post_permalink( get_the_ID() );
- if ( isset( $event_startend_data['evcal_rep_freq'][0] ) ) {
- $event_frequency = $event_startend_data['evcal_rep_freq'][0];
- } else {
- // Event Repeat Type:
- $event_frequency = '';
- }
- $event_rep_num = $event_startend_data['evcal_rep_num'][0]; //Number of repeats:
- $evcal_repeat = $event_startend_data['evcal_repeat'][0]; //Repeat Yes or No
- $evcal_rep_gap = $event_startend_data['evcal_rep_gap'][0]; //Gap between repeats:
- if ( isset( $event_startend_data['repeat_intervals'][0] ) ) {
- $repeat_intervals = $event_startend_data['repeat_intervals'][0];
- } else {
- // repeat intervals days:
- $repeat_intervals = '0';
- }
- if ( isset( $event_startend_data['evo_repeat_wom'][0] ) ) {
- $evo_repeat_wom = $event_startend_data['evo_repeat_wom'][0];
- } else {
- //repeat week of month:
- $evo_repeat_wom = '';
- }
- $evp_repeat_rb = $event_startend_data['evp_repeat_rb'][0]; //Repeat by:day of month(dom),days of week(dow)
- $evp_repeat_rb_wk = $event_startend_data['evp_repeat_rb_wk'][0]; //Repeat by:single day(sing),days of week(dow)
- if ( isset( $event_startend_data['evcal_srow'][0] ) ) {
- $event_start_date = date( 'Y-m-d', $event_startend_data['evcal_srow'][0] );
- $event_start_year = date( 'Y', $event_startend_data['evcal_srow'][0] );
- $event_start_month = date( 'F', $event_startend_data['evcal_srow'][0] );
- }
- if ( isset( $event_startend_data['evcal_erow'][0] ) ) {
- $event_end_date = date( 'Y-m-d', $event_startend_data['evcal_erow'][0] );
- }
- $terms = get_the_terms( get_the_ID(), 'event_type' );
- $cover_img = get_post_meta( get_the_ID(), 'event_image_cover', true );
- $terms_organize = get_the_terms( get_the_ID(), 'event_organizer' );
- $locations = get_the_terms( get_the_ID(), 'event_location' );
- $postviews = get_post_meta( get_the_ID(), 'tie_views', true );
- $commentsnumber = get_comments_number( get_the_ID() );
- $post_a_start_date = get_post_meta( get_the_ID(), 'evcal_srow', true );
- $post_a_end_date = get_post_meta( get_the_ID(), 'evcal_erow', true );
- $meta_id = get_post_meta( get_the_ID(), 'event_image_cover', true );
- if ( !empty( $meta_id ) ) {
- $eventimg = $meta_id;
- } else {
- $eventimg = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
- }
- $events_data['list'][] = array(
- 'event_title' => get_the_title(),
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_link' => $event_link,
- 'event_start' => $event_start_date,
- 'event_end' => $event_end_date,
- 'terms' => $terms,
- 'cover_img' => $cover_img,
- 'terms_organize' => $terms_organize,
- 'locations' => $locations,
- 'postviews' => $postviews,
- 'comments_number' => $commentsnumber,
- 'event_image' => $eventimg,
- );
- if ( $event_frequency && $evcal_repeat == 'yes' ) {
- if ( $event_frequency == 'custom' ) {
- $repeat_intervals = unserialize( $repeat_intervals );
- if ( $repeat_intervals ) {
- foreach ( $repeat_intervals as $rpkey => $rpevents ) {
- if ( $rpkey > 0 ) {
- $post_a_start_date = $rpevents[0];
- $post_a_end_date = $rpevents[1];
- $loop_start_date = date( 'Y-m-d', $post_a_start_date );
- $loop_end_date = date( 'Y-m-d', $post_a_end_date );
- $events_data['list'][] = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $loop_start_date,
- 'event_end' => $loop_end_date,
- );
- }
- }
- }
- }
- if ( $event_frequency == 'daily' ) {
- $k = $evcal_rep_gap;
- for ( $i = 1; $i <= $event_rep_num; $i++ ) {
- if ( $evcal_rep_gap > 1 && $k > 1 ) {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $k . ' day', $event_startend_data['evcal_srow'][0] ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $k . ' day', $event_startend_data['evcal_erow'][0] ) );
- } else {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $i . ' day', $event_startend_data['evcal_srow'][0] ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $i . ' day', $event_startend_data['evcal_erow'][0] ) );
- }
- // $loop_event_start_year = date( 'Y', strtotime( $loop_start_date ) );
- // $loop_event_start_month = date( 'F', strtotime( $loop_start_date ) );
- $events_data['list'][] = array(
- // 'post_a_start_date' => $post_a_start_date,
- // 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $loop_start_date,
- 'event_end' => $loop_end_date,
- );
- $k += $evcal_rep_gap;
- }
- // var_dump($events_data['list']);
- }
- if ( $event_frequency == 'weekly' ) {
- $repeat_intervals = array();
- if ( isset( $event_startend_data['evo_rep_WKwk'][0] ) ) {
- $repeat_intervals = unserialize( $event_startend_data['evo_rep_WKwk'][0] );
- }
- if ( $repeat_intervals && $evp_repeat_rb_wk == 'dow' ) {
- $start_all_days_array = array();
- $kk = $evcal_rep_gap;
- for ( $i = 1; $i <= $event_rep_num; $i++ ) {
- if ( count( $repeat_intervals ) > 0 ) {
- foreach ( $repeat_intervals as $interval_day_number ) {
- $weekday = $weekly_repeat_array[$interval_day_number];
- if ( $evcal_rep_gap > 1 && $kk > 1 ) {
- $kk = $kk - 1;
- $month_loop_start_date = date( 'Y-m-d', strtotime( '' . $weekday . ' +' . $kk . ' week', $event_original_start ) );
- $month_loop_end_date = date( 'Y-m-d', strtotime( '' . $weekday . ' +' . $kk . ' week', $event_original_end ) );
- $startdate_month = date( 'm', $month_loop_start_date );
- $startdate_year = date( 'Y', $month_loop_start_date );
- $start_all_days_array[$month_loop_start_date] = $month_loop_end_date;
- } else {
- $month_loop_start_date = date( 'Y-m-d', strtotime( '' . $weekday . ' +' . $i . ' week', $event_original_start ) );
- $month_loop_end_date = date( 'Y-m-d', strtotime( '' . $weekday . ' +' . $i . ' week', $event_original_end ) );
- $startdate_month = date( 'm', $month_loop_start_date );
- $startdate_year = date( 'Y', $month_loop_start_date );
- $start_all_days_array[$month_loop_start_date] = $month_loop_end_date;
- }
- }
- }
- $kk += $evcal_rep_gap;
- }
- if ( $start_all_days_array ) {
- $final_loop = array();
- $month_counter = 0;
- foreach ( $start_all_days_array as $sdaste => $edate ) {
- $month_counter++;
- // $sdaste = $weekdays_list;
- // $edate = date('Y-m-d', strtotime('+'.$month_counter.' week',strtotime($sdaste)));
- $dates_data = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $sdaste,
- 'event_end' => $edate,
- );
- $final_loop[] = $dates_data;
- }
- }
- // echo'<pre>';
- // print_r( $start_all_days_array);
- // echo'</pre>';
- $events_data['list'] = $final_loop;
- } else {
- $k = $evcal_rep_gap;
- for ( $i = 1; $i <= $event_rep_num; $i++ ) {
- if ( $evcal_rep_gap > 1 && $k > 1 ) {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $k . ' week', $event_startend_data['evcal_srow'][0] ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $k . ' week', $event_startend_data['evcal_erow'][0] ) );
- } else {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $i . ' week', $event_startend_data['evcal_srow'][0] ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $i . ' week', $event_startend_data['evcal_erow'][0] ) );
- }
- $loop_event_start_year = date( 'Y', strtotime( $loop_start_date ) );
- $loop_event_start_month = date( 'F', strtotime( $loop_start_date ) );
- $events_data['list'][] = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $loop_start_date,
- 'event_end' => $loop_end_date,
- );
- $k += $evcal_rep_gap;
- }
- }
- var_dump( $events_data['list'] );
- }
- if ( $event_frequency == 'monthly' ) {
- $repeat_intervals = array();
- if ( isset( $event_startend_data['evo_rep_WK'][0] ) ) {
- $repeat_intervals = unserialize( $event_startend_data['evo_rep_WK'][0] );
- }
- // var_dump($repeat_intervals);
- if ( $repeat_intervals && $evp_repeat_rb == 'dow' ) {
- $evo_repeat_wom_list = array();
- if ( isset( $evo_repeat_wom ) ) {
- $evo_repeat_wom_list = unserialize( $evo_repeat_wom );
- }
- var_dump($evo_repeat_wom_list);
- $start_all_days_array = array();
- $kk = $evcal_rep_gap;
- for ( $i = 0; $i <= $event_rep_num; $i++ ) {
- if ( count( $repeat_intervals ) > 0 && count( $evo_repeat_wom_list ) > 0 ) {
- foreach ( $repeat_intervals as $interval_day_number ) {
- $weekday = $weekly_repeat_array[$interval_day_number];
- if ( $evcal_rep_gap > 1 && $kk > 1 ) {
- $month_loop_start_date = date( 'Y-m-d', strtotime( '+' . $kk . ' month', $event_original_start ) );
- $month_loop_end_date = date( 'Y-m-d', strtotime( '+' . $kk . ' month', $event_original_end ) );
- } else {
- $month_loop_start_date = date( 'Y-m-d', strtotime( '+' . $i . ' month', $event_original_start ) );
- $month_loop_end_date = date( 'Y-m-d', strtotime( '+' . $i . ' month', $event_original_end ) );
- }
- // week of month
- $startdate_month = date( 'm', strtotime( $month_loop_start_date ) );
- $startdate_year = date( 'Y', strtotime( $month_loop_start_date ) );
- foreach ( $evo_repeat_wom_list as $week_repeat_list ) {
- $week_of_month_counter = $week_of_month_repeat[$week_repeat_list];
- // echo $week_of_month_counter." ".$weekday." of $startdate_year-$startdate_month";
- // echo'<br>';
- $start_all_days = date( 'Y-m-d', strtotime( $week_of_month_counter . " " . $weekday . " of $startdate_year-$startdate_month" ) );
- $start_all_days_array[] = $start_all_days;
- }
- if ( $start_all_days_array ) {
- $final_loop = array();
- $month_counter = 0;
- foreach ( $start_all_days_array as $weekdays_list ) {
- $month_counter++;
- $sdaste = $weekdays_list;
- $edate = date( 'Y-m-d', strtotime( '+' . $month_counter . ' month', strtotime( $sdaste ) ) );
- $dates_data = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $sdaste,
- 'event_end' => $edate,
- );
- $final_loop[] = $dates_data;
- }
- }
- $loop_start_date = date( 'Y-m-d', strtotime( $weekday, $month_loop_start_date ) );
- $loop_end_date = date( 'Y-m-d', strtotime( $weekday, $month_loop_end_date ) );
- }
- }
- $kk += $evcal_rep_gap;
- }
- $dates_data = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => date( 'Y-m-d', $event_original_start ),
- 'event_end' => date( 'Y-m-d', $event_original_end ),
- );
- array_push( $final_loop, $dates_data );
- $events_data['list'] = $final_loop;
- } else {
- $k = $evcal_rep_gap;
- for ( $i = 1; $i <= $event_rep_num; $i++ ) {
- if ( $evcal_rep_gap > 1 && $k > 1 ) {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $k . ' month', $event_original_start ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $k . ' month', $event_original_end ) );
- } else {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $i . ' month', $event_original_start ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $i . ' month', $event_original_end ) );
- }
- $events_data['list'][] = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $loop_start_date,
- 'event_end' => $loop_end_date,
- );
- $k += $evcal_rep_gap;
- }
- }
- // var_dump( $events_data['list'] );
- }
- if ( $event_frequency == 'yearly' ) {
- $k = $evcal_rep_gap;
- for ( $i = 1; $i <= $event_rep_num; $i++ ) {
- if ( $evcal_rep_gap > 1 && $k > 1 ) {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $k . ' year', $event_startend_data['evcal_srow'][0] ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $k . ' year', $event_startend_data['evcal_erow'][0] ) );
- } else {
- $loop_start_date = date( 'Y-m-d', strtotime( '+' . $i . ' year', $event_startend_data['evcal_srow'][0] ) );
- $loop_end_date = date( 'Y-m-d', strtotime( '+' . $i . ' year', $event_startend_data['evcal_erow'][0] ) );
- }
- $loop_event_start_year = date( 'Y', strtotime( $loop_start_date ) );
- $loop_event_start_month = date( 'F', strtotime( $loop_start_date ) );
- $events_data['list'][] = array(
- 'post_a_start_date' => $post_a_start_date,
- 'post_a_end_date' => $post_a_end_date,
- 'event_start' => $loop_start_date,
- 'event_end' => $loop_end_date,
- );
- $k += $evcal_rep_gap;
- }
- }
- }
- }
- endwhile;
- wp_reset_postdata();
- var_dump( $events_data['list']);
- get_footer();
Add Comment
Please, Sign In to add comment