I'm using WordPress to organize documentation for a software product I'm supporting and have hit a bit of a snag. I have multiple FAQ documents (saved as pages) that I need to be separate pages but that I want to be able aggregate them into one FAQ master list.
To do this, I installed the "Ninja Page Categories and Tags" plugin so that I could tag each separate page with 'faq'. What I wanted to do then was query for all pages with that tag and then aggregate them into 3 lists, depending on the function of the FAQ: general, instructors, or students. Each result would be sorted based on the ancestor of the individual page.
This is the code I developed:
$instructors = array();
$student = array();
$general = array();
$postsByTag = get_posts('tag=faq&post_type=page&numberposts=0');
foreach($postsByTag as $post) {
setup_postdata($post);
$title = $post->post_title;
$title = str_replace("FAQ: ", "", $title);
$id = $post->ID;
$ancestors = get_post_ancestors($post);
if($post->ancestors && in_array( '386', $post->ancestors)) {
$instructors[] = "<li><a href='". get_permalink()."'>$title</a></li>";
} else if(in_array( '384', $post->ancestors)) {
$students[] ="<li><a href='". get_permalink()."'>$title</a></li>";
} else {
$general[] = "<li><a href='". get_permalink()."'>$title</a></li>";
}
}
The code returns all of the pages tagged with 'faq' but it sorts everything into the "general" category because it seems that get_post_ancestors returns empty, even though I know that's not the case.
What am I doing wrong here? Can anybody help me out? Thanks!
$ancestors? it is not used in your code. there is also no fieldancestorsin the$posttable. – Michael Oct 10 '11 at 18:38get_post_ancestors($id);? – Michael Oct 10 '11 at 19:13$ancestors = get_ancestors($id,'page');codex.wordpress.org/Function_Reference/get_ancestors – Michael Oct 10 '11 at 20:41