-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcpt-demo.php
More file actions
122 lines (112 loc) · 6.02 KB
/
cpt-demo.php
File metadata and controls
122 lines (112 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Plugin Name: Custom Post Type and Meta to AQL preview
* Description: Generate some CPTs for use in the demo
* Plugin URI: https://github.com/ryanwelcher/advanced-query-loop/
* Version: 2.1.1
* Requires at least: 6.1
* Requires PHP: 7.2
* Author: Ryan Welcher
* Author URI: https://www.ryanwelcher.com/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: advanced-query-loop
* Domain Path: /languages
*
* @package AdvancedQueryLoop
*/
// Prevent direct access.
defined( 'ABSPATH' ) || exit;
/**
* Register the post type
*/
function register_stream_post_type() {
$labels = array(
'name' => _x( 'Streams', 'Post type general name', 'advanced-query-loop' ),
'singular_name' => _x( 'Stream', 'Post type singular name', 'advanced-query-loop' ),
'menu_name' => _x( 'Streams', 'Admin Menu text', 'advanced-query-loop' ),
'name_admin_bar' => _x( 'Stream', 'Add New on Toolbar', 'advanced-query-loop' ),
'add_new' => __( 'Add New', 'advanced-query-loop' ),
'add_new_item' => __( 'Add New Stream', 'advanced-query-loop' ),
'new_item' => __( 'New Stream', 'advanced-query-loop' ),
'edit_item' => __( 'Edit Stream', 'advanced-query-loop' ),
'view_item' => __( 'View Stream', 'advanced-query-loop' ),
'all_items' => __( 'All Stream', 'advanced-query-loop' ),
'search_items' => __( 'Search Streams', 'advanced-query-loop' ),
'parent_item_colon' => __( 'Parent Stream:', 'advanced-query-loop' ),
'not_found' => __( 'No Streams found.', 'advanced-query-loop' ),
'not_found_in_trash' => __( 'No Streams found in Trash.', 'advanced-query-loop' ),
'featured_image' => _x( 'Stream Thumbnail', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'advanced-query-loop' ),
'set_featured_image' => _x( 'Set stream thumbnail', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'advanced-query-loop' ),
'remove_featured_image' => _x( 'Remove stream thumbnail', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'advanced-query-loop' ),
'use_featured_image' => _x( 'Use as stream thumbnail', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'advanced-query-loop' ),
'archives' => _x( 'Stream archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'advanced-query-loop' ),
'insert_into_item' => _x( 'Insert into Stream', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'advanced-query-loop' ),
'uploaded_to_this_item' => _x( 'Uploaded to this Stream', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'advanced-query-loop' ),
'filter_items_list' => _x( 'Filter Stream list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'advanced-query-loop' ),
'items_list_navigation' => _x( 'Streams list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'advanced-query-loop' ),
'items_list' => _x( 'Streams list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'advanced-query-loop' ),
);
$args = array(
'labels' => $labels,
'description' => 'Stream custom post type.',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'streams' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'author' ),
'taxonomies' => array( 'category', 'post_tag' ),
'show_in_rest' => true,
'menu_icon' => 'dashicons-format-video',
);
register_post_type( 'twitch-stream', $args );
// Register some post meta.
register_post_meta(
'twitch-stream',
'stream-duration',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
)
);
register_post_meta(
'twitch-stream',
'stream-date',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
)
);
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name', 'advanced-query-loop' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name', 'advanced-query-loop' ),
'search_items' => __( 'Search Genres', 'advanced-query-loop' ),
'all_items' => __( 'All Genres', 'advanced-query-loop' ),
'parent_item' => __( 'Parent Genre', 'advanced-query-loop' ),
'parent_item_colon' => __( 'Parent Genre:', 'advanced-query-loop' ),
'edit_item' => __( 'Edit Genre', 'advanced-query-loop' ),
'update_item' => __( 'Update Genre', 'advanced-query-loop' ),
'add_new_item' => __( 'Add New Genre', 'advanced-query-loop' ),
'new_item_name' => __( 'New Genre Name', 'advanced-query-loop' ),
'menu_name' => __( 'Genre', 'advanced-query-loop' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true,
'rewrite' => array( 'slug' => 'genre' ),
);
register_taxonomy( 'genre', array( 'twitch-stream' ), $args );
}
add_action( 'init', 'register_stream_post_type' );