wppaste
WordPress

get_boundary_post( bool $in_same_term = false, int[]|string $excluded_terms = '', bool $start = true, string $taxonomy = 'category' ): array|null

Since
2.8.0
Source
wp-includes/link-template.php:2201
Retrieves the boundary post.

Description

Boundary being either the first or last post by publish date within the constraints specified by $in_same_term or $excluded_terms.

Parameters

$in_same_termbooloptional
Whether returned post should be in the same taxonomy term. Default false.Default: false
$excluded_termsint[]|stringoptional
Array or comma-separated list of excluded term IDs. Default empty.Default: ''
$startbooloptional
Whether to retrieve first or last post. Default true.Default: true
$taxonomystringoptional
Taxonomy, if $in_same_term is true. Default 'category'.Default: 'category'

Return

array|null
Array containing the boundary post object if successful, null otherwise.

Uses · 6

  • get_post()Retrieves post data given a post ID or post object.
  • is_single()Determines whether the query is for an existing single post.
  • is_attachment()Determines whether the query is for an existing attachment page.
  • taxonomy_exists()Determines whether the taxonomy name exists.
  • wp_get_object_terms()Retrieves the terms associated with the given object(s), in the supplied taxonomies.
  • get_posts()Retrieves an array of the latest posts, or posts matching the given criteria.

Used by · 1

Source

function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {	$post = get_post(); 	if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {		return null;	} 	$query_args = array(		'posts_per_page'         => 1,		'order'                  => $start ? 'ASC' : 'DESC',		'update_post_term_cache' => false,		'update_post_meta_cache' => false,	); 	$term_array = array(); 	if ( ! is_array( $excluded_terms ) ) {		if ( ! empty( $excluded_terms ) ) {			$excluded_terms = explode( ',', $excluded_terms );		} else {			$excluded_terms = array();		}	} 	if ( $in_same_term || ! empty( $excluded_terms ) ) {		if ( $in_same_term ) {			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );		} 		if ( ! empty( $excluded_terms ) ) {			$excluded_terms = array_map( 'intval', $excluded_terms );			$excluded_terms = array_diff( $excluded_terms, $term_array ); 			$inverse_terms = array();			foreach ( $excluded_terms as $excluded_term ) {				$inverse_terms[] = $excluded_term * -1;			}			$excluded_terms = $inverse_terms;		} 		$query_args['tax_query'] = array(			array(				'taxonomy' => $taxonomy,				'terms'    => array_merge( $term_array, $excluded_terms ),			),		);	} 	return get_posts( $query_args );}

History

Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.