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 Post Types UI 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
* template: 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 Post Type Archive Page page title, capability, updated message etc… using the acfe/validate_post_type_archive
hook. Usage example:
/**
* acfe/validate_post_type_archive
*
* @array $args Archive Page settings
*/
filter('acfe/validate_post_type_archive', $args);
filter('acfe/validate_post_type_archive/name=my-post-type', $args);
add_filter('acfe/validate_post_type_archive/name=my-post-type', 'my_post_type_archive_settings');
function my_post_type_archive_settings($args){
/**
* $args = array(
* 'page_title' => 'My Post Type Archive',
* 'menu_title' => 'Archive',
* 'menu_slug' => 'my-post-type-archive',
* 'post_id' => 'my-post-type_archive',
* 'capability' => 'manage_options',
* 'redirect' => false,
* 'parent_slug' => 'edit.php?post_type=my-post-type',
* 'updated_message' => 'My Post Type Archive Saved.',
* )
*/
// change capability
$args['capability'] = 'edit_posts';
// return
return $args;
}