Ok. How about a bounty of $20 (US) for the first person that can provide the above described funtion. I’ll pay via PayPal. If you do decide to take me up on this offer, please post and let the board know that you are working on it. Thanks!
$2o? Seems a lot for so little code. See if this works:
<?php
$parent_array = array();
$current_page = $post->ID;
$parent = 1;
while($parent) {
$page_query = $wpdb->get_row("SELECT ID, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$parent = $current_page = $page_query->post_parent;
if($parent)
$parent_array[] = $page_query->post_parent;
}
?>
$parent_array now holds what you’re after. If run outside The Loop you may need to initialize the $post array; to do that make this the first line of your code:
$post = $wp_query->post;
Now about that $20… Donate the money to a worthy cause. I would suggest the American Cancer Society:
https://www.cancer.org/asp/donate/don_multi_donate.asp
I missed the part about needing it as a function:
<?php
function page_parents() {
global $post, $wp_query, $wpdb;
$post = $wp_query->post;
$parent_array = array();
$current_page = $post->ID;
$parent = 1;
while($parent) {
$page_query = $wpdb->get_row("SELECT ID, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$parent = $current_page = $page_query->post_parent;
if($parent)
$parent_array[] = $page_query->post_parent;
}
return $parent_array;
}
?>
Thanks so much Kafkaesqui. Let me test it and I’ll get back to you shortly. Again thanks!
Kafkaesqui. Your solution works great! Thank you. I will make a donation on your behalf to the ACS.
I hope someone else finds this function useful.
Brilliant!
Thank you for your contribution.
God, I love WordPress, it has simplified my life to no end 😀
Cheers!
PF
Oh,
I don’t have much cash right now, but when I pay down my CC i’ll make that donation too 😉
PF