Make WordPress Core

Opened 13 years ago

Closed 11 years ago

Last modified 11 years ago

#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: kawauso's profile kawauso Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Template Keywords: has-patch
Focuses: Cc:


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.


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)

17037.diff (1.5 KB) - added by solarissmoke 13 years ago.

Download all attachments as: .zip

Change History (5)

#1 @scribu
13 years ago

  • Keywords needs-patch added

I think it should just return false instead.

13 years ago

#2 @solarissmoke
13 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 @c3mdigital
11 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.

#4 @SergeyBiryukov
11 years ago

  • Keywords has-patch added
  • Milestone Awaiting Review deleted
  • Version set to 3.0
Note: See TracTickets for help on using tickets.