Skip to content

Instantly share code, notes, and snippets.

@tormjens
Created November 14, 2016 10:08
Show Gist options
  • Save tormjens/5fdcb09bc9f1da1b56937260aecab3bc to your computer and use it in GitHub Desktop.
Save tormjens/5fdcb09bc9f1da1b56937260aecab3bc to your computer and use it in GitHub Desktop.
Add Post Type Templates (WordPress 4.7) To ACF Add Field Group
<?php
add_filter('acf/location/rule_values/page_template', function($val) {
$post_types = get_post_types(array('public' => true), 'objects');
$new_values = array();
foreach($post_types as $post_type) {
$values = array();
$items = get_page_templates( null, $post_type->name );
foreach($items as $name => $item) {
$values[$item] = $name;
}
$new_values[$post_type->label] = $values;
}
return $new_values;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment