_get_post_ancestors [ WordPress Function ]
| Access: |
|
| Parameters: |
|
| Uses: |
|
| Returns: |
|
| Defined at: |
|
Retrieve post ancestors and append to post ancestors property.
Will only retrieve ancestors once, if property is already set, then nothing will be done. If there is not a parent post, or post ID and post parent ID are the same then nothing will be done.
The parameter is passed by reference, so nothing needs to be returned. The property will be updated and can be referenced after the function is complete. The post parent will be an ancestor and the parent of the post parent will be an ancestor. There will only be two ancestors at the most.
Source
<?php
function _get_post_ancestors(&$_post) {
global $wpdb;
if ( isset($_post->ancestors) )
return;
$_post->ancestors = array();
if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
return;
$id = $_post->ancestors[] = (int) $_post->post_parent;
while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
// Loop detection: If the ancestor has been seen before, break.
if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) )
break;
$id = $_post->ancestors[] = (int) $ancestor;
}
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- (can't we cache _get_post_ancestors()?) - WordPress Trac
... wp_footer hook: 153 queries - 0.403 seconds. the 153 queries (almost all related to _get_post_ancestors()) take as much as a second every now and then.
core.trac.wordpress.org - Function Reference/get post ancestors « WordPress Codex
Description. Retrieve the parents of the post based on the post ID. Usage. <?php get_post_ancestors( $post ) ?> Parameters. $post: (mixed) (required) Post ID or ...
codex.wordpress.org - _get_post_ancestors (WordPress Function) - WPSeek.com
WordPress lookup for _get_post_ancestors, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - _get_post_ancestors() WordPress function reference, arguments ...
Retrieve post ancestors and append to post ancestors property.
queryposts.com