Using WordPress ‘get_boundary_post_rel_link()’ PHP function

The get_boundary_post_rel_link() WordPress PHP function retrieves the boundary post relational link, which can be either the start or end post relational link.

Usage

get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true);

Parameters

  • $title (string) – Optional. Link title format. Default is ‘%title’.
  • $in_same_cat (bool) – Optional. Whether the link should be in the same category. Default is false.
  • $excluded_categories (string) – Optional. Excluded categories IDs. Default is ”.
  • $start (bool) – Optional. Whether to display the link to the first or last post. Default is true.

More information

See WordPress Developer Resources: get_boundary_post_rel_link

Examples

Get a link to the first post in the same category

// Display the first post link in the same category
echo get_boundary_post_rel_link('%title', true, '', true);

Get a link to the last post, excluding a category

// Display the last post link, excluding category with ID 5
echo get_boundary_post_rel_link('%title', false, '5', false);
// Display the first post link with a custom link title format
echo get_boundary_post_rel_link('Go to: %title', false, '', true);

Get a link to the last post in the same category

// Display the last post link in the same category
echo get_boundary_post_rel_link('%title', true, '', false);

Exclude multiple categories

// Display the first post link, excluding categories with IDs 3 and 7
echo get_boundary_post_rel_link('%title', false, '3,7', true);