Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/timperry/acf-post-type-selector/archive/refs/heads/master.zipOn Packagist as iceicetimmy/acf-post-type-selector:
composer require iceicetimmy/acf-post-type-selectorNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
Advanced Custom Fields: acf-post-type-selector Field
Description
Provides the option to select a single or multiple post types
Compatibility
This add-on will work with:
- version 5 and up
- version 4 and up
Installation
This add-on can be treated as both a WP plugin and a theme include.
Plugin
- Copy the 'acf-post-type-selector' folder into your plugins folder
- Activate the plugin via the Plugins admin page
Include
- Copy the 'acf-post-type-selector' folder into your theme folder (can use sub folders). You can place the folder anywhere inside the 'wp-content' directory
- Edit your functions.php file and add the code below (Make sure the path is correct to include the acf-post-type-selector.php file)
ACF Version 4
add_action( 'acf/register_fields', 'my_register_fields' );
function my_register_fields() {
include_once( 'acf-post-type-selector/post-type-selector-v4.php' );
}
ACF Version 5
add_action( 'acf/include_fields', 'my_register_fields' );
function my_register_fields() {
include_once( 'acf-post-type-selector/post-type-selector-v5.php' );
}
Usage
Get Field Value
$post_type_var = 'post_type';
$post_type = get_sub_field( $post_type_var );
Get Field Value and Display Label
<?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="<?php echo get_post_type_archive_link( $post_type ); ?>"><?php echo $post_type_object->label; ?></a></li>
Filter available post types
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 );
Changelog
1.0.1
- Filter available post types
1.0.0
- Support for ACF
v5
0.0.1
- Initial Release.
Releases
1 release.
Tag
Published
v1.0.1
latest
Apr 11, 2018 8 years ago
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.