Opened 14 years ago
Last modified 13 months ago
#22957 new defect (bug)
get_boundary_post Only works from a single page
| Reported by: | pathawks | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 2.8 |
| Severity: | normal | Keywords: | has-patch has-test-info has-unit-tests |
| Cc: | Focuses: | template |
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)
Change History (17)
#3
@
14 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?
This ticket was mentioned in PR #9040 on WordPress/wordpress-develop by @SirLouen.
13 months ago
#8
Refreshing patch
Trac ticket: https://core.trac.wordpress.org/ticket/22957
#9
@
13 months 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
- 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
- Add a couple of posts
- Go to the Home page, check the footer
- 🐞 Null result
Expected Results
- First and last post should be shown in the homepage.
Actual Results
- ✅ Issue resolved with patch.
Additional Notes
- I have refreshed the patch for testing, not updating the deprecated function.
- Some Unit Test for
get_boundary_postcould be useful intests/phpunit/tests/link/getAdjacentPost.phptesting 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.
13 months ago
#11
@
13 months 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
- ✅ 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>'; }
This ticket was mentioned in Slack in #core by sirlouen. View the logs.
13 months ago
#13
@
13 months 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.
13 months ago
This ticket was mentioned in PR #9200 on WordPress/wordpress-develop by @iamadisingh.
13 months 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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)

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