de

wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren




_get_post_ancestors [ WordPress Function ]

_get_post_ancestors ( $_post )
Zugriff:
  • private
Parameter:
  • (object) $_post Post data.
Nutzt:
  • $wpdb
Gibt zurück:
  • (null) When nothing needs to be done.
Definiert in:



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;
    }
}
?>

Beispiele [ wp-snippets.com ]

Top Google Suchergebnisse

Mehr ...

Nutzerduskussionen [ wordpress.org ]

0 Nutzerkommentare

Noch keine. Sei der Erste!

Neu hinzufügen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics