WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get boundary post

Description

It returns object(array of post) by publishing date.

Usage

<?php get_boundary_post$in_same_cat$excluded_categories$start$taxonomy ); ?>

Parameters

$in_same_cat
(boolean) (optiona) Whether same category or not.
Default: false
$excluded_categories
(string) (optiona) Excludes the posts with category IDs.
Default: ''
$start
(boolean) (optiona) 'true' returns first. 'false' returns latest.
Default: true
$taxonomy
(string) (optiona) Taxonomy name, if $in_same_term($in_same_cat) is true.
Default: 'category'

Return Values

  • Post object if successful.
  • Null if global $post is not set.
  • Empty string if no corresponding post exists.

Examples

Link with title of first post in current post's category.

  <?php $first= get_boundary_post(true, , true, 'category');
  if (!empty($first)) { foreach ($first as $post) { ?>
  <a href="<?php echo the_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a>
  <?php }} ?>

Link with title of latest post in current post's category.

  <?php $latest= get_boundary_post(true, , false, 'category');
  if (!empty($latest)) { foreach ($latest as $post) { ?>
  <a href="<?php echo the_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a>
  <?php }} ?>

Notes

get_boundary_post() will set the post pointer to the first post.

Change Log

Since: 2.8.0

Source File

get_boundary_post() is located in wp-includes/link-template.php.

Related

See also index of Function Reference and index of Template Tags.