Destinationパターン(Post→Term)

class code37211
{
	public function __construct()
	{	
		$user = new Model37211() ;
	}//endfunction
}//endclass

class Model37211
{
	public function __construct()
	{
		$args = array(		
			'post_type' => 'post',
			'post__in' => array('18348'),//IDを配列で指定。
		);
		$the_query = new WP_Query($args) ;		

//ループ~表示処理(Viewクラス)の呼び出し。
		if($the_query->have_posts()){
			While($the_query->have_posts()){
				$the_query->the_post();
					$view_obj = new View37211($par) ;
			}
		}//endif
	}//endfunction

}//endclass

class View37211
{
	public function __construct($par)
	{
		the_title() ;
		echo "<br>\n" ;

//次の処理の準備
//投稿に関連付けられているタクソノミーのIDを取得する。
			$myterms = wp_get_object_terms(get_the_ID(), 'region');
			if (!empty($myterms)){
				$foreign_key = array() ;
				foreach ($myterms as $post){
					array_push( $foreign_key , $post->term_id);
				}
			}else{
				return ;
			}//endif		
		
		$par->foreign_key = $foreign_key ;
		$user = new Model37211a($par) ;
		
	}//endfunction
}//endclass

class Model37211a
{
	public function __construct($par)
	{

		$args = array(		
			'include' => $par->foreign_key,
		);
		$the_query = get_terms('region', $args) ;		

//ループ~表示処理(Viewクラス)の呼び出し。
		foreach ($the_query as $term){
			$par->term = $term ;
				$view_obj = new View37211a($par) ;			
		}
	}//endfunction

}//endclass

class View37211a
{
	public function __construct($par)
	{
		echo $par->term->name."<br>\n" ;
		
	}//endfunction
}//endclass