Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#23708 closed defect (bug) (fixed)

get_post_ancestors() no longer works inside loop

Reported by: ripsup's profile ripsup Owned by: nacin's profile nacin
Milestone: 3.5.2 Priority: normal
Severity: normal Version: 3.5
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

Description

When upgrading from 3.3.1 to 3.5.1 we found that get_post_ancestors() no longer works inside the loop like it is suppose to.

This issue stems from the addition line to the beginning of the function (lines 684-685 of /wp-includes/post.php)

if ( ! $post ) 
	return array(); 

I believe this to be a bug, I couldn't find anywhere that this functionality change was desired and breaks anything that relied on this. There was a recent change in Ticket #22882 but this was for a different issue related to this code. If this was an intentional change please tell me where this was that referenced so I better understand where to look in the future.

The fix is just removing these 2 lines.

Change History (6)

#1 @SergeyBiryukov
12 years ago

  • Component changed from General to Post Types
  • Keywords reporter-feedback added

Could you provide a piece of code to reproduce the issue?

#2 @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.5.2
  • Version changed from 3.5.1 to 3.5

This is legitimate.

get_post_ancestors() used to call get_post() immediately, which would convert null/0 etc to the current $post global. Now, it bails.

#3 @nacin
12 years ago

In 1240/tests:

Allow get_post_ancestors() to inspect the $post global, when null/0 is received. see #23708.

#4 @nacin
12 years ago

In 23635:

Allow get_post_ancestors() to inspect the $post global, when null/0 is received. see #23708.

#5 @nacin
12 years ago

  • Keywords has-patch commit added; reporter-feedback removed

#6 @nacin
12 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 23903:

Allow get_post_ancestors() to inspect the $post global, when null/0 is received.

Merges [23635] to the 3.5 branch.
fixes #23708.

Note: See TracTickets for help on using tickets.