future events select by ajax displays only to admins
-
Hi,
I’ve created a custom weekly pagination on the site with custom display.
The pagination is ajax based.When showed to loggedin admin user – all works fine, but with a user that is not logged in future events are not showed and I get an empty query.
Here is the used code:
add_action('wp_ajax_nopriv_dates_events', 'ajax_get_events_between_dates'); add_action('wp_ajax_dates_events', 'ajax_get_events_between_dates'); function ajax_get_events_between_dates() { list($sday, $smon) = explode('/',$_POST['sdate']); list($eday, $emon) = explode('/',$_POST['edate']); $sdate = "$smon/$sday"; $sdate=date('Y-m-d',strtotime($sdate)) ; $edate = "$emon/$eday"; $edate=date('Y-m-d',strtotime($edate)) ; $cat = $_POST['cat']; echo get_events_between($sdate, $edate, $cat); } function get_events_between($start, $end, $cat) { if (empty($cat)) $cat_filter='category="-27866"'; else $cat_filter = 'category="'.$cat.'"'; $html = ''; $events = EM_Events::get(array('date_format' => 'j,M', 'scope'=>"dates ($start,$end)")); if (!empty($events)) { $cur_date = ''; foreach ($events as $event) { if ($event->event_start_date != $cur_date) { if (!empty($cur_date )) $html .= "</section>"; $cur_date = $event->event_start_date; list($year, $mon, $day) = explode('-', $cur_date); $html .= "<section class='date-block'>"; $html .= "<div class='date'><span class='day'>$day</span>".mon2Heb(intval($mon))."</div>"; } $html .= '<article class="date-entry post-entry clearfix" id="event-'.$event->ID.'">'; $html .= '<section class="time">'; $html .= $event->event_start_time; $html .= '</section>'; $html .= '<section class="event-data clearfix">'; $html .= '<h1><a class="trigger closed" href="'.$event->get_permalink().'">'.$event->event_name.'</a></h1>'; $html .= '<!-- <a class="btn" style="float:none;background:#_CATEGORYCOLOR">#_CATEGORYNAME</a> -->'; $html .= '<section class="date-content hidden">'; $html .= $event->post_content; $html .= '</section> </section> </article>'; }; } if (empty($html)) $html = "No events on dates : ".$start." - ".$end; return $html; } add_filter( 'em_events_build_sql_conditions', 'ng_weekly_scope',1,2); function ng_weekly_scope($conditions, $args){ if (!empty($args['scope']) && strpos($args['scope'], 'dates') === 0) { $scope = $args['scope']; $scope = str_replace('dates ', '', $scope); $scope = trim($scope, '()'); list($start, $end) = explode(',', $scope); $conditions['scope'] = " (event_start_date BETWEEN CAST('$start' AS DATE) AND CAST('$end' AS DATE)) OR (event_end_date BETWEEN CAST('$end' AS DATE) AND CAST('$start' AS DATE))"; } return $conditions; } add_filter( 'em_get_scopes','ng_em_scopes',1,1); function ng_em_scopes($scopes){ $my_scopes = array( 'dates' => 'dates' ); return $scopes + $my_scopes; }
Note that the scope is using a custom scope I’ve added coz I thought the problem was scope between dates.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘future events select by ajax displays only to admins’ is closed to new replies.