• Resolved hannit

    (@hannit)


    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 .= &quot;</section>&quot;;
    				$cur_date = $event->event_start_date;
    				list($year, $mon, $day) = explode('-', $cur_date);
    				$html .= &quot;<section class='date-block'>&quot;;
    				$html .= &quot;<div class='date'><span class='day'>$day</span>&quot;.mon2Heb(intval($mon)).&quot;</div>&quot;;
    
    			}
    			$html .= '<article class=&quot;date-entry post-entry clearfix&quot; id=&quot;event-'.$event->ID.'&quot;>';
    			$html .= '<section class=&quot;time&quot;>';
    			$html .= $event->event_start_time;
    			$html .= '</section>';
    			$html .= '<section class=&quot;event-data clearfix&quot;>';
    			$html .= '<h1><a class=&quot;trigger closed&quot; href=&quot;'.$event->get_permalink().'&quot;>'.$event->event_name.'</a></h1>';
    			$html .= '<!-- <a class=&quot;btn&quot; style=&quot;float:none;background:#_CATEGORYCOLOR&quot;>#_CATEGORYNAME</a> -->';
    			$html .= '<section class=&quot;date-content hidden&quot;>';
    			$html .= $event->post_content;
    			$html .= '</section> </section> </article>';
    		};
    	}
    	if (empty($html))
    		$html = &quot;No events on dates : &quot;.$start.&quot; - &quot;.$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.

    https://www.ads-software.com/extend/plugins/events-manager/

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.