Support » Plugin: Events Manager » Next / Previous links don’t work

  • Resolved edmondox

    (@edmondox)


    The normal WordPress next and previous link functions (using the old next_post and previous_post or the newer next_post_link and previous_post_link functions) don’t work on Events Manager single event pages – those functions order by publish date (or ID?) not the event date (so if I publish a new event with a start date in between two existing events the next / previous links put it in the wrong order.

    Is there an EM function (or another means) to have working next / previous links on single event pages that correctly use the event date?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    it’s not possible out the box at the moment. it may be possible with custom coding but unfortunately we are quite limited with regards to custom coding as per the support policy – http://eventsmanagerpro.com/support-policy/

    Ok, well this is what I did which seems to work….

    
    /* code to add working next / previous links to single event pages on WP Event Manager (goes in theme / single-event.php) */
    
    // use the global variable $wpdb to access the WordPress database
    global $wpdb;
    
    // get all events from the wp_em_events table, ordered by date and time
    $all_event_ids = $wpdb->get_results("SELECT post_id FROM wp_em_events WHERE 1 ORDER BY event_start_date, event_start_time ASC");
    
    // get this post ID (a single event page)
    $postid = get_queried_object_id();
    
    // index is used to count through $all_event_ids array until this post ID is found
    $index = 0;
    foreach($all_event_ids as $event_id){
    
    	// stop looping when index of this post found
    	if($event_id->post_id == $postid) break;
    	
    	// or continue looping
    	$index ++;
    	
    }
    
    //  now...
    //  $all_event_ids[$index+1]->post_id is ID of next event 
    //  $all_event_ids[$index-1]->post_id is ID previous event
    
    // show 'previous' link if this event is not first 
    if($index > 0) {
    	echo '<a href="' . get_the_permalink( $all_event_ids[$index-1]->post_id ) . '">< previous event</a>&nbsp;';
    }
    
    // show 'next' link if this event is not last of all events
    if($index < count($all_event_ids)) {
    	echo '<a href="' . get_the_permalink( $all_event_ids[$index+1]->post_id ) . '"> | next event ></a>';
    }
    
    Plugin Support caimin_nwl

    (@caimin_nwl)

    NetWebLogic Support

    I think your query is wrong. Try this:

    $all_event_ids = $wpdb->get_results("SELECT post_id FROM wp_em_events ORDER BY event_start_date ASC, event_start_time ASC")

    Thanks Caimin, it’s not wrong, it works fine (though the WHERE is redundant).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Next / Previous links don’t work’ is closed to new replies.