Home / Admin / CPT _DIR – Gravity View
Duplicate Snippet

Embed Snippet on Your Site

CPT _DIR – Gravity View

ismail daugherty PRO
<10
Code Preview
php
<?php
/**
 * WPCode Snippet: GravityView Views CPT Registration
 * Description: Registers custom post type for GravityView with full REST API support
 * Location: Run Everywhere
 * Priority: 0
 */
defined( 'ABSPATH' ) || exit;
add_action( 'init', function() {
    $labels = [
        'name'                     => 'GravityView Views',
        'singular_name'            => 'View',
        'menu_name'                => 'GV Views Sync',
        'all_items'                => 'All Views',
        'add_new'                  => 'Add New',
        'add_new_item'             => 'Add New View',
        'edit_item'                => 'Edit View',
        'new_item'                 => 'New View',
        'view_item'                => 'View Details',
        'search_items'             => 'Search Views',
        'not_found'                => 'No views found',
        'not_found_in_trash'       => 'No views found in Trash',
        'item_updated'             => 'View updated',
    ];
    
    register_post_type( 'gv_views_sync', [
        'labels'              => $labels,
        'description'         => 'GravityView configurations with layouts, settings, and field mappings',
        'public'              => false,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'menu_position'       => 32,
        'menu_icon'           => 'dashicons-editor-table',
        
        // REST API support - CRITICAL for WhalSync
        'show_in_rest'        => true,
        'rest_base'           => 'gv-views-sync',
        'rest_controller_class' => 'WP_REST_Posts_Controller',
        
        // Security
        'capability_type'     => 'post',
        'map_meta_cap'        => true,
        
        // Features - MUST include 'custom-fields' for meta exposure
        'supports'            => [ 'title', 'custom-fields', 'revisions' ],
        'hierarchical'        => false,
        'has_archive'         => false,
        'rewrite'             => false,
        'query_var'           => true,
        'exclude_from_search' => true,
        'can_export'          => true,
        'delete_with_user'    => false,
    ] );
} );

Comments

Add a Comment