WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7029 closed defect (bug) (fixed)

get_post_ancestors() is broken

Reported by: temoto Owned by:
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.5.1
Component: General Keywords: has-patch dev-feedback
Focuses: Cc:

Description

wp-includes/post.php:195
Bugs:

  • Params description do not match code.
  • Function doesn't work because get_post() requires argument.
/**
 * get_post_ancestors() - Retrieve ancestors for a post
 *
 * @package WordPress
 * @subpackage Post
 * @since 2.5
 *
 * @param string $field {@internal Missing Description}}
 * @param int|object &$post post ID or post object
 * @return array of ancestor IDs
 */
function get_post_ancestors($post) {
	$post = get_post();

	if ( !empty($post->ancestors) )
		return $post->ancestors;

	return array();
}

Attachments (1)

7029.diff (590 bytes) - added by mdawaffe 7 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 @Otto427 years ago

  • Keywords needs-patch added
  • Summary changed from Bad get_post_ancestors() to get_post_ancestors() is broken

I think this would fix it:

function get_post_ancestors($post) {
	if (is_integer($post)) $post = get_post($post);

	if ( !empty($post->ancestors) )
		return $post->ancestors;

	return array();
}

comment:2 @mdawaffe7 years ago

get_post() can take post IDs or post object, (or be told to get the global $post by passing it 0).

Attached. I think the argument to get_post_ancestors() should not be a reference, but I'm not positive.

@mdawaffe7 years ago

comment:3 @mdawaffe7 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

comment:4 @ryan7 years ago

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

(In [8019]) get_post_ancestors() fixes. fixes #7029 for trunk

comment:5 @ryan7 years ago

(In [8020]) get_post_ancestors() fixes. fixes #7029 for 2.5

comment:6 @ryan7 years ago

  • Milestone changed from 2.5.2 to 2.9

Milestone 2.5.2 deleted

comment:7 @westi7 years ago

  • Milestone changed from 2.9 to 2.6
Note: See TracTickets for help on using tickets.