You are viewing an old revision of this post, from September 2, 2015 @ 14:41:55. See below for differences between this version and the current revision.

Post type selector for Advanced Custom Fields

As seen on Github: https://github.com/thomasdebruin/acf-post-type-selector

Plugin

  1. Copy the 'acf-post-type-selector' folder into your plugins folder
  2. Activate the plugin via the Plugins admin page

Include

  1. 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
  2. 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)
    add_action( 'acf/register_fields', 'my_register_fields' );
    
    function my_register_fields() {
    
         include_once( 'acf-post-type-selector}/acf-post-type-selector.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>

 

Revisions

  • September 2, 2015 @ 14:41:55 [Current Revision] by PeterLugg
  • September 2, 2015 @ 14:41:55 by PeterLugg

Revision Differences

There are no differences between the September 2, 2015 @ 14:41:55 revision and the current revision. (Maybe only post meta information was changed.)

Tags: , ,

No comments yet.

Leave a Reply