I’m using $child->ID on 2.8.x myself. I’ll look into it for you 😉
$child->ID seems to work fine in 2.9-RC1. Maybe it has something to do with how you use the $childID array after that block?
Thread Starter
jon
(@adiant)
Thank you for your help. In 2.8.6, $child->ID gives me a number. In 2.9, $child->ID gives me NULL. And $child itself gives me the same number as 2.8.6 did for $child->ID.
I didn’t test RC1.
That’s pretty bizarre. And I can tell you just by looking at the diff, get_children() itself has not changed in 2.9 final.
http://core.trac.wordpress.org/changeset?new=12415@trunk/wp-includes/post.php&old=12163@trunk/wp-includes/post.php
$p = get_page($child);
That line doesn’t make any sense to me. I’m pretty sure that’s causing the problem.
Thread Starter
jon
(@adiant)
Thank you very much for this. I’ll sit down and try and rewrite this “properly”.
You’re welcome! (And I got the chance to test more of my future upgrades)
Thread Starter
jon
(@adiant)
For the record, here is the final working (both 2.8.x and 2.9) version:
function children_title2id() {
$children = get_children("post_type=page&post_parent=" . get_the_ID());
foreach ($children as $child) {
$t = strtolower($child->post_title);
// Title points at pageID
$childID[$t] = $child->ID;
};
return $childID;
};
The missing post_type=page that miqrogroove earlier picked up on is required according to the Codex. But it is the $p = get_page($child); that was really killing it.
It creates an array where the keys are the page titles in lower-case. And the associated value for each key is the page ID for the page.