WordPress.org

Ready to get started?Download WordPress

Forums

if current page is in branch of sub-pages (4 posts)

  1. rhysbwaller
    Member
    Posted 4 years ago #

    Hello

    I am trying to test if the current page has a particular top-level page in its ancestry. I am using the get_post_ancestors function to build the array, then checking if it has the page id of 9 contained via an in_array function. Below is my code, but im not getting the output when the condition is met.

    if(in_array(9,get_post_ancestors($post->ID))) {
    				// Do Something
    }

    Is my syntax and logic ok?

    Thanks

  2. vtxyzzy
    Member
    Posted 4 years ago #

    Looks OK to me. Did you dump out $post->ID to see if it contains what you think it should? You could also assign the output of get_post_ancestors to a variable and dump that.

  3. rhysbwaller
    Member
    Posted 4 years ago #

    whats the best way to dump the variables? Do I need to use FirePHP in order to retrieve php variables with Firefox and Firebug, or is there a better way to handle it?

    Thanks for the help

  4. vtxyzzy
    Member
    Posted 4 years ago #

    I usually just put a print_r($variable); in for quick testing, but Firefox offers a lot more flexibility. I mostly develop in IE because that's what the majority of viewers use and if I get it right for IE, Firefox generally is OK.

Topic Closed

This topic has been closed to new replies.

About this Topic