Ticket #7029 (closed defect (bug): fixed)
get_post_ancestors() is broken
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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
Change History
- Keywords needs-patch added
- Summary changed from Bad get_post_ancestors() to get_post_ancestors() is broken
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.
- Status changed from new to closed
- Resolution set to fixed
Note: See
TracTickets for help on using
tickets.


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(); }