ACF Extended adds a new location which create an Archive Options Page for any custom post type. Field groups can be displayed after the title, after the list or in the sidebar.
In order to use this Field Group Location, you must enable the “Archive Page” setting in the Post Type UI. See Dynamic Post Types documentation.
Create a set of rules to determine edit screens
and |
Fields values are saved using a custom post ID based on the post type name: {post_type_name}_archive
.
You can retrieve fields values using the common get_field()
function. Usage example:
// Post Type: My Post Type
$textarea = get_field('textarea', 'my-post-type_archive');
$fields = get_fields('my-post-type_archive');
It is possible to access the Post Type Archive fields values in the front-end without having to set the custom Post ID, using the have_archive(): the_archive()
loop. Usage example:
/*
* Template: 'archive-my-post-type.php' or 'single-my-post-type.php'
*/
if(have_archive()):
while(have_archive()): the_archive();
// Get field value
$textarea = get_field('textarea');
endwhile;
endif;
/*
* Template: Anywhere
*/
if(have_archive('my-post-type')):
while(have_archive('my-post-type')): the_archive();
// Get field value
$textarea = get_field('textarea');
endwhile;
endif;
It is possible to change the capability required to manage the Post Type Archive Page using the acfe/post_type_archive_capability
. The default capability is manage_options
. Usage example:
/*
* @string $capability Capability Name
* @string $name Post Type Name
*/
filter('acfe/post_type_archive_capability', $capability, $name);
filter('acfe/post_type_archive_capability/name=my-post-type', $capability, $name);
add_filter('acfe/post_type_archive_capability/name=my-post-type', 'my_post_type_archive_cap', 10, 2);
function my_post_type_archive_cap($capability, $name){
// Return
return 'manage_options';
}