Skip to content

Instantly share code, notes, and snippets.

@andrewahead4
Created October 2, 2015 11:14

Revisions

  1. andrewahead4 created this gist Oct 2, 2015.
    42 changes: 42 additions & 0 deletions WP REST Enabled Custom Post Type
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    add_action( 'init', 'register_cpt_blog_entry' );

    function register_cpt_blog_entry() {

    $labels = array(
    'name' => _x( 'Blog Entries', 'blog_entry' ),
    'singular_name' => _x( 'Blog Entry', 'blog_entry' ),
    'add_new' => _x( 'Add New', 'blog_entry' ),
    'add_new_item' => _x( 'Add New Blog Entry', 'blog_entry' ),
    'edit_item' => _x( 'Edit Blog Entry', 'blog_entry' ),
    'new_item' => _x( 'New Blog Entry', 'blog_entry' ),
    'view_item' => _x( 'View Blog Entry', 'blog_entry' ),
    'search_items' => _x( 'Search Blog Entries', 'blog_entry' ),
    'not_found' => _x( 'No blog entries found', 'blog_entry' ),
    'not_found_in_trash' => _x( 'No blog entries found in Trash', 'blog_entry' ),
    'parent_item_colon' => _x( 'Parent Blog Entry:', 'blog_entry' ),
    'menu_name' => _x( 'Blog Entries', 'blog_entry' ),
    );

    $args = array(
    'labels' => $labels,
    'hierarchical' => false,
    'description' => 'An individual blog entry',
    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'comments' ),
    'taxonomies' => array( 'txblogentry' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_rest' => true,

    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
    );

    register_post_type( 'blog_entry', $args );
    }