#17037 closed defect (bug) (invalid)
get_the_title() will pass an empty title and invalid post ID to 'the_title' filter on invalid post ID
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0 |
Component: | Template | Keywords: | has-patch |
Focuses: | Cc: |
Description
get_the_title()
has a workaround for when an invalid post ID is passed, setting the title to an empty string and post ID to the requested ID, then passing this to 'the_title' filter.
Example:
function testme() { var_dump( get_the_title( 99999 ) ); } function filterme( $title ) { return "[$title]"; } add_action( 'wp_head', 'testme' ); add_filter( 'the_title', 'filterme' );
Is there a reason for this odd functionality?
Attachments (1)
Change History (5)
#2
@
14 years ago
- Keywords has-patch added; needs-patch removed
This was done in #11435:
Fix notices in get_the_title() when passed an invalid id. Also ensure that the filter gets the invalid id so a plugin can supply a default title instead.
I fail to see why you would want a default title for a post that doesn't exist...
#3
@
12 years ago
- Keywords has-patch removed
- Resolution set to invalid
- Status changed from new to closed
- Version 3.1 deleted
Couldn't this be handled by doing a check if ( '0' == $post_id ) in your get_the_title filter? And I also fail to see why you would want a default title for a post that doesn't exist.
Note: See
TracTickets for help on using
tickets.
I think it should just return false instead.