Ticket #7029 (closed defect: fixed)

Opened 4 months ago

Last modified 1 month ago

get_post_ancestors() is broken

Reported by: temoto Assigned to: anonymous
Priority: normal Milestone: 2.6
Component: General Version: 2.5.1
Severity: normal Keywords: has-patch dev-feedback
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

7029.diff (0.6 kB) - added by mdawaffe on 05/30/08 18:18:44.

Change History

05/30/08 17:51:00 changed by Otto42

  • keywords set to needs-patch.
  • 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();
}

05/30/08 18:18:19 changed by mdawaffe

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.

05/30/08 18:18:44 changed by mdawaffe

  • attachment 7029.diff added.

05/30/08 18:19:22 changed by mdawaffe

  • keywords changed from needs-patch to has-patch dev-feedback.

05/30/08 20:31:45 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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

05/30/08 20:31:58 changed by ryan

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

07/15/08 16:24:07 changed by ryan

  • milestone changed from 2.5.2 to 2.9.

Milestone 2.5.2 deleted

07/30/08 20:35:19 changed by westi

  • milestone changed from 2.9 to 2.6.