[WORDPRESS] WordPress 상위 템플릿 이름을 가져옵니다
WORDPRESSWordPress 상위 템플릿 이름을 가져옵니다
해결법
-
1.
You can try this for get parent page template name /********** GET PAGES BY PARAMS ************/ /*-- Get root parent of a page --*/ function get_root_page($page_id) { global $wpdb; $parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE post_type='page' AND ID = '$page_id'"); if ($parent == 0) return $page_id; else return get_root_page($parent); } /*-- Get page name by ID --*/ function get_page_name_by_ID($page_id) { global $wpdb; $page_name = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = '$page_id'"); return $page_name; } /*-- Get page ID by Page Template --*/ function get_page_ID_by_page_template($template_name) { global $wpdb; $page_ID = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = '$template_name' AND meta_key = '_wp_page_template'"); return $page_ID; } /* -- Get page ID by Custom Field Value -- */ function get_page_ID_by_custom_field_value($custom_field, $value) { global $wpdb; $page_ID = $wpdb->get_var(" SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '$custom_field' AND (wpostmeta.meta_value like '$value,%' OR wpostmeta.meta_value like '%,$value,%' OR wpostmeta.meta_value like '%,$value' OR wpostmeta.meta_value = '$value') AND wposts.post_status = 'publish' AND wposts.post_type = 'page' LIMIT 0, 1"); return $page_ID; }
from https://stackoverflow.com/questions/39862290/get-wordpress-parent-template-name by cc-by-sa and MIT license
'WORDPRESS' 카테고리의 다른 글
[WORDPRESS] WordPress에서 모든 사용자를 위해 작동하도록 Ajax를 가져옵니다 (0) | 2020.11.20 |
---|---|
[WORDPRESS] WordPress 편집기 Div 속성 제거 (0) | 2020.11.20 |
[WORDPRESS] WordPress에서 사용자 지정 소셜 쉐어 카운트 캐싱 (0) | 2020.11.20 |
[WORDPRESS] WordPress : 분류학 용어의 계층 적 목록 (0) | 2020.11.20 |
[WORDPRESS] 댓글에서 사용자 역할을 표시하는 방법에 대한 WordPress (0) | 2020.11.20 |