private function create_taxonomy_replace_tag($post_id, $permalink)
{
$search = array();
$replace = array();
$taxonomies = CPTP_Util::get_taxonomies(true);
// %taxnomomy% -> parent/child
// 運用でケアすべきかも。
foreach ($taxonomies as $taxonomy => $objects) {
if (false !== strpos($permalink, '%' . $taxonomy . '%')) {
$terms = get_the_terms($post_id, $taxonomy);
if ($terms and !is_wp_error($terms)) {
$parents = array_map(array(__CLASS__, 'get_term_parent'), $terms);
// 親の一覧
$newTerms = array();
foreach ($terms as $key => $term) {
if (!in_array($term->term_id, $parents)) {
$newTerms[] = $term;
}
}
// このブロックだけで良いはず。
$term_obj = reset($newTerms);
// 最初のOBjectのみを対象。
$term_slug = $term_obj->slug;
if (isset($term_obj->parent) and 0 != $term_obj->parent) {
$term_slug = CPTP_Util::get_taxonomy_parents_slug($term_obj->parent, $taxonomy, '/', true) . $term_slug;
}
}
if (isset($term_slug)) {
$search[] = '%' . $taxonomy . '%';
$replace[] = $term_slug;
}
}
}
return array('search' => $search, 'replace' => $replace);
}