Tribe__Events__Main::get_event_link( WP_Post $post, string $mode = 'next', mixed $anchor = false )
Get a “previous/next post” link for events. Ordered by start date instead of ID.
Contents
Parameters
- $post
-
(WP_Post) (Required) The post/event.
- $mode
-
(string) (Optional) Either 'next' or 'previous'.
Default value: 'next'
- $anchor
-
(mixed) (Optional)
Default value: false
Return
(string) The link (with <a> tags).
Source
File: src/Tribe/Main.php
public function get_event_link( $post, $mode = 'next', $anchor = false ) {
$link = null;
$event = $this->get_closest_event( $post, $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).
*
* @var string $link
* @var WP_Post $post
* @var string $mode (typically "previous" or "next")
* @var string $anchor
*/
return apply_filters( 'tribe_events_get_event_link', $link, $post, $mode, $anchor );
}