Support

Home Forums Event Espresso Premium Display in front-end the list of events created by a specific author

Display in front-end the list of events created by a specific author

Posted: March 2, 2016 at 10:13 am

Viewing 10 reply threads


JacquesMivi

March 2, 2016 at 10:13 am

Hello,

I would like to allow an Events Author to see in the front-end – in his account page for example – the list of all the events he created so that he can access them quickly. Then I would like to be able to display only his ongoing or future events, only his past events, etc.

In a second part of development (if possible), I also would like to display the registrants for each events.

Do you know how could I do these 2 points please?
Many thanks in advance


Josh

  • Support Staff

March 2, 2016 at 12:34 pm

Hi JacquesMivi,

You could get started with using the built in WordPress post author archives. You add something like this to your functions file:

function my_ee_custom_post_author_archive( &$query )
{
    if ( $query->is_author )
        $query->set( 'post_type', 'espresso_events' );
    remove_action( 'pre_get_posts', 'my_ee_custom_post_author_archive' ); // run once!
}
add_action( 'pre_get_posts', 'my_ee_custom_post_author_archive' );

Then it will include event posts for the author when you browse to yoursite.com/author/username.

You can display the registrants for each of the events by using the [ESPRESSO_EVENT_ATTENDEES] shortcode.


JacquesMivi

March 3, 2016 at 11:28 pm

Hi Josh,

Thanks fot he solution, I’m sure it can work. However I didn’t manage to make it work until now because we created our own page and url replacing /author/username/
I think I have to add the connected author ID as a paramter in the function. Do you know how I could do this ?

Here is our website if you need to see more details: http://www.viviarto.com

Thanks a lot!


Josh

  • Support Staff

March 4, 2016 at 6:41 am

You wouldn’t necessarily change the above code, but instead you could use something like this:

https://wordpress.org/support/topic/let-contributors-see-own-posts-on-front-end#post-1507982


JacquesMivi

March 14, 2016 at 1:08 am

Hi Josh,

Thanks for all your answers, I finally managed to display the list of events in the Account page of the organizers. I didn’t manage to display the list of registrants yet thgouhg, I’m still working on it.

In the meantime, do you know if I can use the shortcode [ESPRESSO_EVENT_ATTENDEES] in the email sent to the organizers each time a registration is apporved in EE4? If I can’t, how could I do to send an automatic email to an organizer to send him the list of all registrants he has for each of his event? My need is to let the organizers know frequently who is precisely attending their events.

Thanks for your help


JacquesMivi

March 14, 2016 at 4:28 am

Hello,

In a front end account page template I display list of events of a user, and I add the list of attendees. Its almost working. I have a problem on status, the participant appears in each shortcode. Example

Liste de vos ateliers
Atelier Danse et Théâtre – Modifier
Confirmé
Jacques Jahnichen
En attente
Jacques Jahnichen
Annulé
Jacques Jahnichen
Refusé
Jacques Jahnichen

The code

<?php
$author_query = array(
'author' 		 => $current_user->ID,
'post_type'      => 'espresso_events',
'post_status' => 'publish, private',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$author_posts = new WP_Query($author_query);

if ($author_posts->have_posts()) {
echo "<h4>Liste de vos ateliers</h4>";
echo "<ul>"; 
while($author_posts->have_posts()) : $author_posts->the_post();
$edit_post = add_query_arg( 'post', get_the_ID(), get_permalink( 4745 + $_POST['_wp_http_referer'] ) );
?>
<li>
<a href="<?php the_permalink(); ?>" rel="bookmark" t title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
- <a href="<?php echo $edit_post; ?>">Modifier</a>
<ul>
Confirmé
<?php echo do_shortcode( '[ESPRESSO_EVENT_ATTENDEES event_id="' . get_the_ID() . '" status=RAP]' ); ?>
En attente
<?php echo do_shortcode( '[ESPRESSO_EVENT_ATTENDEES event_id="' . get_the_ID() . '" status=RNA]' ); ?>	
Annulé
<?php echo do_shortcode( '[ESPRESSO_EVENT_ATTENDEES event_id="' . get_the_ID() . '" status=RCN]' ); ?>	
Refusé
<?php echo do_shortcode( '[ESPRESSO_EVENT_ATTENDEES event_id="' . get_the_ID() . '" status=RDC]' ); ?>	
</ul>
</li>  		
<?php
endwhile;
echo "</ul>"; 
}
wp_reset_query();  // Restore global post data stomped by the_post().

In back end, this user is only accepted. Have you a solution ?


JacquesMivi

March 14, 2016 at 4:46 am

After some investigations.
The first shortcode give the results for all the next shortcodes. I cannot reset shortcode (I have tried wp_reset_query(); and wp_reset_postdata();)

Have you an idea ?


JacquesMivi

March 14, 2016 at 11:59 am

After some works, I give up shortcode because I got strange behaviour and I wanted have tickets before to have attendees.
Last question (For today 😉 What is the field to know if the registration is Approved, Waiting, Cancelled ?

Here my code

$author_query = array(
			'author' 			 => $id_user,
			'post_type'     	 => 'espresso_events',
			'post_status'		 => 'publish, private',
			'posts_per_page' 	 => -1,
			'caller_get_posts'	 => 1
			);
		$author_posts = new WP_Query($author_query);
		
		if ($author_posts->have_posts()) {
			global $wpdb, $post;
			
			echo "<h4>Liste de vos ateliers</h4>";
			echo "<ul>"; 
			while($author_posts->have_posts()) : $author_posts->the_post();
				$edit_post = add_query_arg( 'post', get_the_ID(), get_permalink( 4745 + $_POST['_wp_http_referer'] ) );
				?>
				<li>
					<a href="<?php the_permalink(); ?>" rel="bookmark" t title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
					- <a href="<?php echo $edit_post; ?>">Modifier</a>
					
					<?php      
						echo '<ul class="ticket-list">';								
						$sql_tickets = "SELECT TKT_name, st_esp_ticket.TKT_ID ";
						$sql_tickets .= "FROM {$wpdb->prefix}esp_ticket ";
						$sql_tickets .= "INNER JOIN {$wpdb->prefix}esp_datetime_ticket ";
						$sql_tickets .= "ON {$wpdb->prefix}esp_ticket.TKT_ID = {$wpdb->prefix}esp_datetime_ticket.TKT_ID ";
						$sql_tickets .= "INNER JOIN {$wpdb->prefix}esp_datetime ";
						$sql_tickets .= "ON {$wpdb->prefix}esp_datetime.DTT_ID = {$wpdb->prefix}esp_datetime_ticket.DTT_ID ";
						$sql_tickets .= "WHERE {$wpdb->prefix}esp_datetime.EVT_ID = %d ";
			
						$tickets = $wpdb->get_results( $wpdb->prepare( $sql_tickets, get_the_ID()));						
						
						if (count($tickets)==0) {
							echo "Aucun ticket";						
						} else {						
							foreach($tickets as $ticket){
								$TKT_name = $ticket->TKT_name;
								$TKT_ID = $ticket->TKT_ID;
								$html = "Ticket : " . $TKT_name;
								echo $html;
								
									if(is_singular()){
										echo '<ul class="attendee-list">';
									
										$sql_attendees = "SELECT ATT_fname, ATT_lname, ATT_email ";
										$sql_attendees .= "FROM {$wpdb->prefix}esp_attendee_meta ";
										$sql_attendees .= "INNER JOIN {$wpdb->prefix}esp_registration ";
										$sql_attendees .= "ON {$wpdb->prefix}esp_attendee_meta.ATT_ID = {$wpdb->prefix}esp_registration.ATT_ID ";
										$sql_attendees .= "WHERE {$wpdb->prefix}esp_registration.TKT_ID = %d";
										
										$attendees = $wpdb->get_results( $wpdb->prepare( $sql_attendees, $TKT_ID));
										foreach($attendees as $attendee){
											$fname = $attendee->ATT_fname;
											$lname = $attendee->ATT_lname;
											$email = $attendee->ATT_email;
											$html = '<li><span>'. $fname .' '. $lname . ' - ' . $email . '</span></li>';
											echo $html;
										}
										echo '</ul>';	
									}
							}
							wp_reset_query();  // Restore global post data stomped by the_post().
						}
						echo '</ul>';
					?>
							
				</li>  		
				<?php
			endwhile;
			echo "</ul>"; 
		}
		wp_reset_query();  // Restore global post data stomped by the_post().


Tony

  • Support Staff

March 15, 2016 at 4:48 am

After some works, I give up shortcode because I got strange behaviour and I wanted have tickets before to have attendees.

Shortcodes aren’t designed to be used that way, alot of people do, but its not how they are expected to be used, so its best to switch away from doing this sooner rather than later 🙂

What is the field to know if the registration is Approved, Waiting, Cancelled ?

It’s the STS_ID within {prefix}esp_registration.

However I would highly recommend taking a look into use our models for this, take a look here:

http://developer.eventespresso.com/docs/model-querying/

http://developer.eventespresso.com/docs/ee-model-objects-and-custom-post-types/

http://developer.eventespresso.com/docs/using-ee4-model-objects/

It does almost all of this for you.


JacquesMivi

March 18, 2016 at 11:10 am

I will certainly study that.
Thanks a lot tony.


Tony

  • Support Staff

March 18, 2016 at 11:50 am

You’re most welcome 🙂

Viewing 10 reply threads

The support post ‘Display in front-end the list of events created by a specific author’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso