• Resolved BingoBingo

    (@bingobingo)


    The query and the loop works.
    How can I display the start date of the event in addition to the title?
    Thank you
    Ingo

    ....
    
    $args = array( 
    	'post_type' => 'event',
    	'meta_query' => array(
    	'relation' => 'OR',
    		array(
    			'key'       => 'Referent1',
    			'value'     => $Referenten->id,
    			'compare'   => '=',
    		),
    		array(
    			'key'       => 'Referent2',
    			'value'     => $Referenten->id,
    			'compare'   => '=',
    		),
    ....
    		)
    	)
    );
    
    	$query = new WP_Query( $args );
    	$RListe=$RListe .'<div>';	
    
    	while($query->have_posts()):
    		$query->next_post();
    		$id = $query->post->ID;
    	...
    		$RListe=$RListe .'; ' .get_the_title($id) '</br>';
    		
    		
    	endwhile;
    	
    ....	

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

Viewing 11 replies - 1 through 11 (of 11 total)
  • Stonehenge Creations

    (@duisterdenhaag)

    global $EM_Event;
    echo date_i18n("d-m-Y", $EM_Event->start_date);
    Thread Starter BingoBingo

    (@bingobingo)

    Thank you very much

    I have adapted the code (see below). But it will always show 01-01-1970 for each event and not the date of the event.

    global $EM_Event;
    ….

    $args = array(
    ‘post_type’ => ‘event’,
    ‘meta_query’ => array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘Referent1’,
    ‘value’ => $Referenten->id,
    ‘compare’ => ‘=’,
    ),
    array(
    ‘key’ => ‘Referent2’,
    ‘value’ => $Referenten->id,
    ‘compare’ => ‘=’,
    ),
    ….
    )
    )
    );

    $query = new WP_Query( $args );
    $RListe=$RListe .'<div>’;

    while($query->have_posts()):
    $query->next_post();
    $id = $query->post->ID;

    $RListe=$RListe .’; ‘ .get_the_title($id) .date_i18n(“d-m-Y”, $EM_Event->start_date) .'</br>’;

    endwhile;

    ….

    Stonehenge Creations

    (@duisterdenhaag)

    global $EM_Event;

    Call the EM_Object first, but IN your Query. You need to call $EM_Event for that post. 01-01-1970 means empty!

    while($query->have_posts()):
    $query->next_post();
    $id = $query->post->ID;
    global $EM_Event;
    echo $EM_Event->start_date;
    Thread Starter BingoBingo

    (@bingobingo)

    I call the object in the query. And I placed the output in two places. Now no date is displayed

    ….

    $args = array(
    ‘post_type’ => ‘event’,
    ‘meta_query’ => array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘Referent1’,
    ‘value’ => $Referenten->id,
    ‘compare’ => ‘=’,
    ),
    array(
    ‘key’ => ‘Referent2’,
    ‘value’ => $Referenten->id,
    ‘compare’ => ‘=’,
    ),
    ….
    )
    )
    );

    $query = new WP_Query( $args );
    $RListe=$RListe .'<div>’;

    while($query->have_posts()):
    $query->next_post();
    $id = $query->post->ID;
    global $EM_Event;
    echo $EM_Event->start_date;

    $RListe=$RListe .get_the_title($id) .’; ‘ .$EM_Event->start_date .'</br>’;

    endwhile;

    ….

    Stonehenge Creations

    (@duisterdenhaag)

    Is anything outputted if you do this before the endwhile:

    echo '<pre>'; print_r($EM_Event); '</pre>';

    Stonehenge Creations

    (@duisterdenhaag)

    I just read your first post again… lease tell me what are you trying to out put and where? It might help.

    Thread Starter BingoBingo

    (@bingobingo)

    Hello Patrick

    I have events with up to three speakers (Referent1, Referent2, Referent3). I would like a list of all speakers and their events with date.
    Speaker A; Event c; 2016-02-11
    Speaker A; Event g; 2017-03-02
    Speaker B; Event c; 2016-02-11

    Output on screen or in a file

    echo ‘

    '; print_r ($ EM_Event); '</ pre>' has an effect, see here:
    https://aktionskreis-energie.de/referenten-events/
    
    
    My code:
    
    
    function Ref_event_list(){ 
    $RListe='';
    $args = array(
    	'meta_key' 	=> 'last_name',
    	'order'         => 'ASC',
    	'orderby'       => 'meta_value',
    	'meta_query'    => array(
    		array(
    			'key'       => 'referent',
    			'value'     => 'true',
    			'compare'   => '=',
    		),
    	),
    
    );
    
    $user_query = new WP_User_Query( $args );
    if ( ! empty( $user_query->results ) ) {
        foreach ( $user_query->results as $Referenten) {
       	
    $args = array( 
    	'post_type' => 'event',
    	'meta_query' => array(
    	'relation' => 'OR',
    		array(
    			'key'       => 'Referent1',
    			'value'     => $Referenten->id,
    			'compare'   => '=',
    		),
    		array(
    			'key'       => 'Referent2',
    			'value'     => $Referenten->id,
    			'compare'   => '=',
    		),
    		array(
    			'key'       => 'Referent3',
    			'value'     => $Referenten->id,
    			'compare'   => '=',
    		)
    	)
    );
    
    	// The Query
    	$query = new WP_Query( $args );
    	$RListe=$RListe  .'<div>';	
    	
    	while($query->have_posts()):// The Loop
    		$query->next_post();
    		global $EM_Event;
    		$id = $query->post->ID;
    		echo $EM_Event->start_date;
    		   	
    		$RListe=$RListe .$Referenten->titel_dr.'; '  .$Referenten->first_name .'; ' .$Referenten->last_name ;// the speaker
    	
    		$RListe=$RListe .'; ' .get_the_title($id) .'; '  .$EM_Event->start_date .'</br>';	
    		echo '<pre>'; print_r($EM_Event); '</pre>';
    		
    	endwhile;
    	wp_reset_postdata();// Reset Post Data
    	$RListe=$RListe  .'</div>';
    		}
    } 
      	return $RListe; }
    Stonehenge Creations

    (@duisterdenhaag)

    That could be done much easier. You would just have to stop “seeing the referents as people”. LOL. ??

    What I mean is, if each referent preaches in just one church (all in the same or each in his own, doesn’t really matter), then in the eyes of EM the location has become somewhat obsolete. You won’t need that functionality for your website.

    By default the Event has #1 and the location #2 priority, but you could change that around through your setup. So, if you change the slug “location” to “referent” you could use that as the starting point.

    Try to think of it this way:
    You organise events on different dates, but on several locations (referents). You could then group the locations (referents) together to show their upcoming events (preaches) with the short code [location post_id=”xxx”]

    This will leave you with the EM functionalities such as listing all events (preaches) by date or by location (referent). Google Maps would then not point to the church, but the referent. So if they preach in different locations, you can still use Google Maps. Otherwise I would stop using the locations map and just display a static google map image. Seeing the problems some users have integrating Google Maps API, that could turn out to be a less frustrating option as well. ??

    Another possibility is to start “seeing referents as categories”. But then not Event Categories, but regular WordPress blog categories. Basically the same idea as Locations, but a bit less flexible, because a lot of that is automated by WordPress itself (such as archives and category info pages). Also a category allows for less info than an EM location does.
    By default EM does not support that, but I have a simple snippet that will allow EM to use blog categories…
    Then you can group the services together by category/referent. Using blog categories will allow you to use those outside of the EM loop, btw.

    So in short, it’s mostly the way you look at the things you’re working with. Yes, WordPress and Events Manager named certain functionalities a certain way, but that does not necessarily mean you have to use them that way.

    Stonehenge Creations

    (@duisterdenhaag)

    Oh, btw,
    You $EM_Event output shows empty info, so it turns out you are actually not in the right loop… Hard to say how to correct that without access to the source ??

    Again, stop trying to recreate the hard work that EM can do for you, if you change your approach ??

    Thread Starter BingoBingo

    (@bingobingo)

    Wow, thank you for your thoughts …!!
    Unfortunately, we are playing in a different league. I’m just a hobbyist and I made the site with a lot of effort.
    Your ideas seem very plausible to me. But it would take me a long, long time to realize that. So I try to adapt existing code. The people need short-term the list. That’s all.
    Yes, $ EM_Event is probably empty and probably can not display a date.

    Thank you very much!!

    Stonehenge Creations

    (@duisterdenhaag)

    Actually, what you are doing now is taking more time.. But the choice is yours, of course.

    Simply create location/referents use shortcodes. That’s it.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How can I dispay the date?’ is closed to new replies.