acf-post-functions.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * acf_get_post_templates |
| 5 | * |
| 6 | * Returns an array of post_type => templates data. |
| 7 | * |
| 8 | * @date 29/8/17 |
| 9 | * @since 5.6.2 |
| 10 | * |
| 11 | * @param void |
| 12 | * @return array |
| 13 | */ |
| 14 | function acf_get_post_templates() { |
| 15 | |
| 16 | // Defaults. |
| 17 | $post_templates = array( |
| 18 | 'page' => array() |
| 19 | ); |
| 20 | |
| 21 | // Loop over post types and append their templates. |
| 22 | if( method_exists('WP_Theme', 'get_page_templates') ) { |
| 23 | $post_types = acf_get_post_types(); |
| 24 | foreach( $post_types as $post_type ) { |
| 25 | $templates = wp_get_theme()->get_page_templates( null, $post_type ); |
| 26 | if( $templates ) { |
| 27 | $post_templates[ $post_type ] = $templates; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // Return. |
| 33 | return $post_templates; |
| 34 | } |