Make WordPress Core

Opened 13 years ago

Last modified 7 days ago

#22957 new defect (bug)

get_boundary_post Only works from a single page

Reported by: pathawks's profile pathawks Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Posts, Post Types Keywords: has-patch has-test-info has-unit-tests
Focuses: template Cc:

Description

I was trying to use get_boundary_post in my theme to display a link to the first and last posts, but it does not work from the homepage. Unless called from a single post, get_boundary_post will return NULL.

I can't see any reason for this behavior, or any good way around it.

Attachments (2)

22957.diff (1.1 KB) - added by pathawks 13 years ago.
get_boundary_post from any page
get_boundary_post.diff (1.1 KB) - added by pathawks 10 years ago.

Download all attachments as: .zip

Change History (17)

#1 @SergeyBiryukov
13 years ago

  • Component changed from General to Template

#2 @SergeyBiryukov
13 years ago

Has been this way since introduction in [10815] (#8703).

#3 @pathawks
13 years ago

What is the reason for this?

I understand why start_post_rel_link might want to only fire on single posts, but I see no reason to limit the avaliability of get_boundary_post.

On a related note, when there is nothing to return, why does it return NULL rather than FALSE like similar functions?

Last edited 13 years ago by pathawks (previous) (diff)

@pathawks
13 years ago

get_boundary_post from any page

#4 @pathawks
13 years ago

  • Keywords has-patch added
  • Version set to trunk

#5 @SergeyBiryukov
13 years ago

  • Version changed from trunk to 2.8

#6 @nacin
11 years ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

#7 @chriscct7
10 years ago

  • Keywords needs-testing added

This ticket was mentioned in PR #9040 on WordPress/wordpress-develop by @SirLouen.


3 weeks ago
#8

Refreshing patch

Trac ticket: https://core.trac.wordpress.org/ticket/22957

#9 @SirLouen
3 weeks ago

  • Keywords has-test-info added; needs-testing removed

Test Report

Description

✅ This report validates that the indicated patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/9040.diff

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 137.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins: None activated
  • Plugins:
    • Boundary Tester 1.0.0
    • Test Reports 1.2.0

Testing Instructions

  1. I'm providing, in the Artifacts, the code to test. Use this in a plugin, theme's functions.php, or wherever you can execute code
  2. Add a couple of posts
  3. Go to the Home page, check the footer
  4. 🐞 Null result

https://i.imgur.com/XZCBrrL.png

Expected Results

  1. First and last post should be shown in the homepage.

Actual Results

  1. ✅ Issue resolved with patch.

Additional Notes

  • I have refreshed the patch for testing, not updating the deprecated function.
  • Some Unit Test for get_boundary_post could be useful in tests/phpunit/tests/link/getAdjacentPost.php testing for the cases commented in this report (homepage)

By removing this:

! $post || ! is_single() || is_attachment()

I wondered if there could be a location, where it should not be displayed, that could cause a regression. As @SergeyBiryukov has pointed out, this was born like this in [10815] with not many explanations from #8703. So basically can say that this has been historically a bug.

Supplemental Artifacts

Code for testing

add_action('wp_footer', 'test_boundary_posts');

function test_boundary_posts() {
    $first_post_array = get_boundary_post(true, '', true);
    $last_post_array = get_boundary_post(true, '', false);

    echo '<div style="padding: 20px;">';
    echo '<h3>Boundary Post Test</h3>';
    
    if ( ! empty($first_post_array)) {
        $first_post = $first_post_array[0];
        echo '<p>First Post:' . $first_post->post_title . '</p>';
    } else {
        echo '<p>First post not found (NULL or empty result returned).</p>';
    }
    
    if ( ! empty($last_post_array)) {
        $last_post = $last_post_array[0];
        echo '<p>Last Post:' . $last_post->post_title . '</p>';
    } else {
        echo '<p>Last post not found (NULL or empty result returned).</p>';
    }
    
    echo '</div>';
}

This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.


3 weeks ago

#11 @devasheeshkaul
3 weeks ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/9040

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 136.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ✅ Issue resolved with patch.

Supplemental Artifacts

Code used for testing:

<?php
add_action('wp_footer', 'test_boundary_posts');

function test_boundary_posts() {
    $first_post_array = get_boundary_post(true, '', true);
    $last_post_array = get_boundary_post(true, '', false);

    echo '<div style="padding: 20px;">';
    echo '<h3>Boundary Post Test</h3>';
    
    if ( ! empty($first_post_array)) {
        $first_post = $first_post_array[0];
        echo '<p>First Post:' . $first_post->post_title . '</p>';
    } else {
        echo '<p>First post not found (NULL or empty result returned).</p>';
    }
    
    if ( ! empty($last_post_array)) {
        $last_post = $last_post_array[0];
        echo '<p>Last Post:' . $last_post->post_title . '</p>';
    } else {
        echo '<p>Last post not found (NULL or empty result returned).</p>';
    }
    
    echo '</div>';
}

Footer Output:

https://i.ibb.co/Nd0sH074/Screenshot-2025-06-23-at-10-37-51-PM.png

Last edited 3 weeks ago by devasheeshkaul (previous) (diff)

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


11 days ago

#13 @SirLouen
11 days ago

  • Keywords needs-unit-tests added

As per today's bug scrub, this ticket is mostly ready to be delivered but still I think that some Unit Test would be ideal to round it before final delivery.

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


11 days ago

This ticket was mentioned in PR #9200 on WordPress/wordpress-develop by @iamadisingh.


7 days ago
#15

  • Keywords has-unit-tests added; needs-unit-tests removed

Trac ticket: #22957

Patch used: https://github.com/WordPress/wordpress-develop/pull/9040

---

## Description

Added unit tests that verify get_boundary_post() works correctly from non-singular pages (homepage, archive pages) and maintains backward compatibility with single post pages.

## Testing Instructions:
Run the following command to verify the tests:

npm run test:php -- --filter=Tests_Link_GetBoundaryPost
Note: See TracTickets for help on using tickets.