カスタム投稿の先祖を表示

呼び出す側

$par2->gen_id = '18661';
$par2->post_type = 'reference' ;
$user = new Model37639() ;
    $user->generation($par2) ;

呼び出される側(クラス)

class Model37639 extends WP_Query
{
	public function generation($par2)
	{
		$ance = array() ;
		$ance = get_ancestors($par2->gen_id, $par2->post_type) ;
		//$cnt = count($ance);
		$ance = array_reverse($ance) ;
		$k = 0 ;
		While ( !empty($ance[$k])) {
			$par2->id = $ance[$k] ;
			$par2->k = $k  ;
			$View_obj = new View37639a($par2) ;
			$k = $k +1 ;
		}//endwhile
	}//endfunction

}//endclass

class View37639a
{
	public function __construct($par2)
	{
		$postslist = get_post($par2->id) ;
 		setup_postdata($postslist);
		echo $postslist->post_title."<br>\n" ;
		
	}//endfunction
}//endclass

参考文献

参考記事