Provides the option to select a single or multiple post types
This add-on will work with:
This add-on can be treated as both a WP plugin and a theme include.
add_action( 'acf/register_fields', 'my_register_fields' );
function my_register_fields() {
include_once( 'acf-post-type-selector/post-type-selector-v4.php' );
}
add_action( 'acf/include_fields', 'my_register_fields' );
function my_register_fields() {
include_once( 'acf-post-type-selector/post-type-selector-v5.php' );
}
$post_type_var = 'post_type';
$post_type = get_sub_field( $post_type_var );
<?php
// get post type fields
$post_type_var = 'post_type';
$post_type = get_sub_field( $post_type_var );
// get post type label
$post_type_object = get_post_type_object( $post_type ); ?>
<li><a href="https://github.com/TimPerry/acf-post-type-selector/blob/master/<?php echo get_post_type_archive_link( $post_type ); ?>"><?php echo $post_type_object->label; ?></a></li>
By default, only post types with parameter public
will be shown. If you need to show non-public post types use the filter post_type_selector_post_types
as described below. This filter also allows you to remove post types from the list.
add_filter( 'post_type_selector_post_types', function( $post_types, $field ) {
$post_types['foo'] = get_post_type_object( 'foo' );
unset( $post_types['post'] );
return $post_types;
}, 10, 2 );
v5