Forums

[resolved] 2.9: change to get_children() ? (11 posts)

  1. jonradio
    Member
    Posted 2 years ago #

    In Version 2.8.x of WordPress, this worked:

    global $post;
    	$children = get_children("post_parent=" . $post->ID);
    	foreach ($children as $child) {
    		$p = get_page($child);
    		$t = strtolower($p->post_title);
    		//  Title points at pageID
    		$childID[$t] = $child->ID;
    	};

    But in Version 2.9, the second to last line had to be changed to = $child;

    Anyone have any information on this change?

  2. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    I'm using $child->ID on 2.8.x myself. I'll look into it for you ;)

  3. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    $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?

  4. jonradio
    Member
    Posted 2 years ago #

    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.

  5. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    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

  6. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    ...

  7. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    ...

  8. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    $p = get_page($child);

    That line doesn't make any sense to me. I'm pretty sure that's causing the problem.

  9. jonradio
    Member
    Posted 2 years ago #

    Thank you very much for this. I'll sit down and try and rewrite this "properly".

  10. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    You're welcome! (And I got the chance to test more of my future upgrades)

  11. jonradio
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic