public function test_url_to_postid_cpt_hierarchial_term($structure)
{
update_option($this->post_type . "_structure", $structure);
register_taxonomy($this->taxonomy, $this->post_type, array("public" => true, "hierarchial" => true));
register_post_type($this->post_type, array("public" => true));
$user_id = $this->factory->user->create();
$id = $this->factory->post->create(array('post_type' => $this->post_type, "post_name" => rand_str(12), "post_author" => $user_id));
$cat_id = $this->factory->category->create();
wp_set_post_categories($id, array($cat_id));
$term_id = 0;
$slug_list = array();
for ($i = 0; $i < 4; $i++) {
$term_id = $this->factory->term->create(array("taxonomy" => $this->taxonomy, "parent" => $term_id));
$slug_list[] = get_term($term_id, $this->taxonomy)->slug;
}
wp_set_post_terms($id, get_term($term_id, $this->taxonomy)->slug, $this->taxonomy);
do_action('wp_loaded');
/** @var WP_Rewrite $wp_rewrite */
global $wp_rewrite;
$wp_rewrite->flush_rules();
$single_term_link = get_permalink($id);
$this->assertEquals($id, url_to_postid(get_permalink($id)));
//全てのタームにチェックが付いていた場合。
wp_set_post_terms($id, $slug_list, $this->taxonomy);
$this->assertEquals($id, url_to_postid(get_permalink($id)));
$this->assertEquals(get_permalink($id), $single_term_link);
}