Make WordPress Core

Changeset 65151


Ignore:
Timestamp:
10/31/2026 09:08:36 PM (5 hours ago)
Author:
lancewillett
Message:

Posts, Post Types: Allow boundary post lookups outside single posts.

Allow get_boundary_post() to return the first or last post on non-singular pages. Retain the missing-post guard when $in_same_term needs a current post, and continue rejecting unknown taxonomies.

Add coverage for non-singular lookups and the missing-post case.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/9200, ​https://github.com/WordPress/wordpress-develop/pull/9040

Props pathawks, sirlouen, iamadisingh, mukesh27, devasheeshkaul.
Fixes #22957.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r64488 r65151  
    22102210 */
    22112211function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
     2212        if ( ! taxonomy_exists( $taxonomy ) ) {
     2213                return null;
     2214        }
     2215
    22122216        $post = get_post();
    22132217
    2214         if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
     2218        if ( $in_same_term && ! $post ) {
    22152219                return null;
    22162220        }
Note: See TracChangeset for help on using the changeset viewer.