Tribe__Events__Adjacent_Events::get_event_link( string $mode = 'next', mixed $anchor = false )

Get a “previous/next post” link for events. Ordered by start date instead of ID.


Parameters

$mode

(string) (Optional) Either 'next' or 'previous'.

Default value: 'next'

$anchor

(mixed) (Optional)

Default value: false


Top ↑

Return

(string) The link (with <a> tags).


Top ↑

Source

File: src/Tribe/Adjacent_Events.php

	public function get_event_link( $mode = 'next', $anchor = false ) {
		$link  = null;
		$event = $this->get_closest_event( $mode );

		// If we successfully located the next/prev event, we should have precisely one element in $results
		if ( $event ) {
			if ( ! $anchor ) {
				$anchor = apply_filters( 'the_title', $event->post_title, $event->ID );
			} elseif ( strpos( $anchor, '%title%' ) !== false ) {
				// get the nicely filtered post title
				$title = apply_filters( 'the_title', $event->post_title, $event->ID );

				// escape special characters used in the second parameter of preg_replace
				$title = str_replace(
					array(
						'\\',
						'$',
					),
					array(
						'\\\\',
						'\$',
					),
					$title
				);

				$anchor = preg_replace( '|%title%|', $title, $anchor );
			}

			$link = '<a href="' . esc_url( tribe_get_event_link( $event ) ) . '">' . $anchor . '</a>';
		}

		/**
		 * Affords an opportunity to modify the event link (typically for the next or previous
		 * event in relation to $post).
		 *
		 * @since 4.6.12
		 *
		 * @param string  $link
		 * @param int     $current_event_id
		 * @param WP_Post $event
		 * @param string  $mode (typically "previous" or "next")
		 * @param string  $anchor
		 */
		return apply_filters( 'tribe_events_get_event_link', $link, $this->current_event_id, $event, $mode, $anchor );
	}

Top ↑

Changelog

Changelog
Version Description
4.6.12 Introduced.