| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
/* |
| 8 |
* Creating a function to create our CPT |
| 9 |
*/ |
| 10 |
|
| 11 |
function wdk_custom_post_type() { |
| 12 |
|
| 13 |
// Set UI labels for Custom Post Type |
| 14 |
$labels = array( |
| 15 |
'name' => _x( 'WDK-Listings', 'Post Type General Name', 'wpdirectorykit' ), |
| 16 |
'singular_name' => _x( 'Listing', 'Post Type Singular Name', 'wpdirectorykit' ), |
| 17 |
'menu_name' => __( 'WDK-Listings', 'wpdirectorykit' ), |
| 18 |
'parent_item_colon' => __( 'Parent Listing', 'wpdirectorykit' ), |
| 19 |
'all_items' => __( 'All Listings', 'wpdirectorykit' ), |
| 20 |
'view_item' => __( 'View Listing', 'wpdirectorykit' ), |
| 21 |
'add_new_item' => __( 'Add New Listing', 'wpdirectorykit' ), |
| 22 |
'add_new' => __( 'Add New', 'wpdirectorykit' ), |
| 23 |
'edit_item' => __( 'Edit Listing', 'wpdirectorykit' ), |
| 24 |
'update_item' => __( 'Update Listing', 'wpdirectorykit' ), |
| 25 |
'search_items' => __( 'Search Listing', 'wpdirectorykit' ), |
| 26 |
'not_found' => __( 'Not Found', 'wpdirectorykit' ), |
| 27 |
'not_found_in_trash' => __( 'Not found in Trash', 'wpdirectorykit' ), |
| 28 |
); |
| 29 |
|
| 30 |
// Set other options for Custom Post Type |
| 31 |
|
| 32 |
$args = array( |
| 33 |
'label' => __( 'Listings', 'wpdirectorykit' ), |
| 34 |
'description' => __( 'Listing', 'wpdirectorykit' ), |
| 35 |
'labels' => $labels, |
| 36 |
// Features this CPT supports in Post Editor |
| 37 |
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'elementor' ), |
| 38 |
// You can associate this CPT with a taxonomy or custom taxonomy. |
| 39 |
'taxonomies' => array( ), |
| 40 |
/* A hierarchical CPT is like Pages and can have |
| 41 |
* Parent and child items. A non-hierarchical CPT |
| 42 |
* is like Posts. |
| 43 |
*/ |
| 44 |
'hierarchical' => false, |
| 45 |
'public' => true, |
| 46 |
'show_ui' => false, |
| 47 |
'show_in_menu' => true, |
| 48 |
'show_in_nav_menus' => true, |
| 49 |
'show_in_admin_bar' => true, |
| 50 |
'menu_position' => 30, |
| 51 |
'can_export' => true, |
| 52 |
'has_archive' => false, |
| 53 |
'exclude_from_search' => true, |
| 54 |
'publicly_queryable' => true, |
| 55 |
'capability_type' => 'page', |
| 56 |
'show_in_rest' => true, |
| 57 |
'menu_icon' => 'dashicons-category', |
| 58 |
); |
| 59 |
|
| 60 |
// Registering your Custom Post Type |
| 61 |
register_post_type( 'wdk-listing', $args ); |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
/* Hook into the 'init' action so that the function |
| 66 |
* Containing our post type registration is not |
| 67 |
* unnecessarily executed. |
| 68 |
*/ |
| 69 |
|
| 70 |
add_action( 'init', 'wdk_custom_post_type', 0 ); |
| 71 |
|
| 72 |
|