Forums

get_ancestors issue - can see where to fix, just not WHAT to fix (3 posts)

  1. missmoxie
    Member
    Posted 1 year ago #

    Today I upgraded a client to 3.1 from 3.04. She's running multi-site. The functions.php file contains a section that is using get_ancestors and the entire site, including the dashboard gives me the double-bird now and won't load. I have no clue what to change to make it that function work again. When I comment out that portion, the dashboard reloads and the site does, too, except obviously with errors in the header call.

    Do you have any bright ideas? :) I'm desperate to get her site back online and have had very, very little luck finding anything in Google or these forums. A few other things *kind of* like this, but with no resolutions.

    This is the error I receive:
    Fatal error: Cannot redeclare get_ancestors() (previously declared in /home/account_name/public_html/wp-includes/taxonomy.php:3055) in /home/account_name/public_html/wp-content/themes/account_name/functions.php on line 153

    And this is the snippet it's referring to:

    function get_ancestors ($p) {
        $parent = $p->post_parent;
        $ancestors = array ();
        while ($parent != '0') {
    		if ($parent) {
    			$ancestors[] = $parent;
    		}
            $p = get_post ($parent);
            $parent = $p->post_parent;
        }
        return $ancestors;
    }

    I tried changing get_ancestors to get_post_ancestors, but it broke again and I wasn't sure what to do. I think something to do with wp-includes/post.php, but this is just a little beyond my scope.

    I'd appreciate any insight. Thank you!

  2. missmoxie
    Member
    Posted 1 year ago #

    Naturally, as SOON as I hit post, the answer is discovered and it's all fixed now.

    From my friend:

    it looks like get_ancestors() in this case is a custom function in the functions file; however a core function called get_ancestors() was introduced with WP 3.1, so it looks like you're getting a conflict there. The custom function is only expecting a single parameter (as a post, it looks like), whereas the core get_ancestors() expects two object parameters:

    http://codex.wordpress.org/Function_Reference/get_ancestors

    Probably the easiest thing to do would be to rename the custom function to something like get_my_ancestors(), and amend any calls to it.

    So I did that and all seems to be well. :)

  3. joefletcher
    Member
    Posted 8 months ago #

    Thanks - I renamed that same function, and worked for me.

Topic Closed

This topic has been closed to new replies.

About this Topic