/**
* For Post type 'nzschoo''elicos''university''majors''news'
*/
$archive_url = '';
// major 포스트 타입은 무조건 아카이브로
if ($post_type === 'major' || $post_type === 'news') {
$archive_url = get_post_type_archive_link($post_type);
$post_type_obj = get_post_type_object($post_type);
} else {
// 그 외 포스트 타입은 카테고리 우선
$taxonomies = get_object_taxonomies($post_type, 'objects');
// 공개된 택소노미 중에서 첫 번째 term 찾기
foreach ($taxonomies as $taxonomy) {
if ($taxonomy->public) {
$terms = get_the_terms(get_the_ID(), $taxonomy->name);
if ($terms && !is_wp_error($terms)) {
$category_url = get_term_link($terms[0]);
// 카테고리 URL에 post_type 파라미터 추가
$archive_url = add_query_arg('post_type', $post_type, $category_url);
$button_text = $terms[0]->name . ' 목록보기';
break; // 첫 번째로 찾은 카테고리 사용
}
}
}
}
// 카테고리가 없으면 포스트 타입 아카이브로
if (!$archive_url) {
$archive_url = get_post_type_archive_link($post_type);
$post_type_obj = get_post_type_object($post_type);
}
// 최종 폴백
if (!$archive_url) {
$archive_url = home_url();
}
?>