• Resolved jeeltcraft

    (@jeeltcraft)


    Hi, I have to display booked events for each author on the author page, I tried to replicate the my-bookings.php code as follows but I can’t get this to display the bookings using the author id, here is the code I’ve put in the author page:

    <?php do_action('em_template_my_bookings_header'); ?>
    <?php
    		$EM_Person = new EM_Person( $author_id );
    		$EM_Bookings = $EM_Person->get_bookings(false, apply_filters('em_bp_attending_status', 1));
    		$bookings_count = count($EM_Bookings->bookings);
    		if($bookings_count > 0){
    			//Get events here in one query to speed things up
    			$event_ids = array();
    			foreach($EM_Bookings as $EM_Booking){
    				$event_ids[] = $EM_Booking->event_id;
    			}
    		}				
    
    		$limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 100;//Default limit
    		$page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
    		$offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
    		echo $EM_Notices;
    		?>
    some html
    
    				<?php if ( $bookings_count >= $limit ) : ?>
    				<div class='tablenav'>
    					<?php 
    					if ( $bookings_count >= $limit ) {
    						$link = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%'), false); //don't html encode, so em_paginate does its thing
    						$bookings_nav = em_paginate( $link, $bookings_count, $limit, $page);
    						echo $bookings_nav;
    					}
    					?>
    					<div class="clear"></div>
    				</div>
    				<?php endif; ?>
    				<div class="clear"></div>
    				<?php if( $bookings_count > 0 ): ?>
    				<div class='table-wrap'>
    				<table id='dbem-bookings-table' class='widefat post fixed'>
    					<thead>
    						<tr>
    							<th class='manage-column' scope='col'><?php _e('Event', 'events-manager'); ?></th>
    							<th class='manage-column' scope='col'><?php _e('Date', 'events-manager'); ?></th>
    							<th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
    							<th class='manage-column' scope='col'><?php _e('Status', 'events-manager'); ?></th>
    							<th class='manage-column' scope='col'>&nbsp;</th>
    						</tr>
    					</thead>
    					<tbody>
    						<?php 
    						$today = new DateTime(); // This object represents current date/time
    						$today->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison
    						$rowno = 0;
    						$event_count = 0;
    						$nonce = wp_create_nonce('booking_cancel');
    						foreach ($EM_Bookings as $EM_Booking) {
    							/* @var $EM_Booking EM_Booking */
    							$EM_Event = $EM_Booking->get_event();						
    							if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
    
    								if ($EM_Event->start > $today->getTimestamp())
    								{
    								$rowno++;
    								?>
    								<tr>
    									<td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
    									<td><?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->start ); ?></td>
    									<td><?php echo $EM_Booking->get_spaces() ?></td>
    									<td>
    										<?php echo $EM_Booking->get_status(); ?>
    									</td>
    									<td>
    										<?php
    										$cancel_link = '';
    										if( !in_array($EM_Booking->booking_status, array(2,3)) && get_option('dbem_bookings_user_cancellation') && $EM_Event->get_bookings()->has_open_time() ){
    											$cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
    											$cancel_link = '<a class="em-bookings-cancel" href="'.$cancel_url.'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel','events-manager').'</a>';
    										}
    										echo apply_filters('em_my_bookings_booking_actions', $cancel_link, $EM_Booking);
    										?>
    									</td>
    								</tr>								
    								<?php
    								}
    							}
    							do_action('em_my_bookings_booking_loop',$EM_Booking);
    							$event_count++;
    						}
    						?>
    					</tbody>
    				</table>
    				</div>
    				<?php else: ?>
    					La bancarella non si trova in alcun mercato.
    				<?php endif; ?>
    			<?php if( !empty($bookings_nav) && $bookings_count >= $limit ) : ?>
    			<div class='tablenav'>
    				<?php echo $bookings_nav; ?>
    				<div class="clear"></div>
    			</div>
    			<?php endif; ?>
    			<?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • I can’t get this to display the bookings using the author id

    Bookings are never registered to an author, only to an event of course.

    So you will need to create a separate loop-filter for that.

    Thread Starter jeeltcraft

    (@jeeltcraft)

    Can’t the $EM_person variable be used for that?
    If not:
    Is there any documentation on how to set up the filter?
    Thanks for the quick answer Patrick!

    Nope, you would first have to get all the events by that author and then query the bookings for that result.

    Thread Starter jeeltcraft

    (@jeeltcraft)

    It worked manipulating the $EM_Person object… now i just need to modify the template to show a map with events and not the table… I’ll have a try and then ask again for help if needed.
    I really appreciated your answer Patrick ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Showing booked events on author page’ is closed to new replies.