-
Notifications
You must be signed in to change notification settings - Fork 18
/
example-field-setup.php
81 lines (75 loc) · 2.88 KB
/
example-field-setup.php
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
<?php
/*
* Example setup for cmb2 custom field : post search ajax.
*/
/**
* Define the metabox and field configurations.
*
* @param array $meta_boxes
* @return array
*/
function cmb2_post_search_ajax_metaboxes_example() {
$example_meta = new_cmb2_box( array(
'id' => 'cmb2_post_search_ajax_field',
'title' => __( 'Related Posts', 'cmb2' ),
'object_types' => array( 'post' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
) );
$example_meta->add_field( array(
'name' => __( 'Example Multiple', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_multiple',
'type' => 'post_search_ajax',
'desc' => __( '(Start typing post title)', 'cmb2' ),
// Optional :
'limit' => 10, // Limit selection to X items only (default 1)
'sortable' => true, // Allow selected items to be sortable (default false)
'query_args' => array(
'post_type' => array( 'post' ),
'post_status' => array( 'publish' ),
'posts_per_page' => -1
)
) );
$example_meta->add_field( array(
'name' => __( 'Example Single', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_single',
'type' => 'post_search_ajax',
'desc' => __( '(Start typing post title)', 'cmb2' ),
// Optional :
'limit' => 1, // Limit selection to X items only (default 1)
'sortable' => false, // Allow selected items to be sortable (default false)
'query_args' => array(
'post_type' => array( 'post' ),
'post_status' => array( 'publish' ),
'posts_per_page' => -1
)
) );
$example_meta->add_field( array(
'name' => __( 'Test user multiple', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_user_multiple',
'type' => 'post_search_ajax',
'desc' => __( '(Start typing post title)', 'cmb2' ),
// Optional :
'limit' => 10, // Limit selection to X items only (default 1)
'sortable' => true, // Allow selected items to be sortable (default false)
'object_type' => 'user', // Define queried object type (Available : post, user, term - Default : post)
'query_args' => array(
'blog_id' => '1',
)
) );
$example_meta->add_field( array(
'name' => __( 'Test user single', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_user_single',
'type' => 'post_search_ajax',
'desc' => __( '(Start typing post title)', 'cmb2' ),
// Optional :
'limit' => 1, // Limit selection to X items only (default 1)
'sortable' => false, // Allow selected items to be sortable (default false)
'object_type' => 'user', // Define queried object type (Available : post, user, term - Default : post)
'query_args' => array(
'role' => 'Administrator'
)
) );
}
add_action( 'cmb2_init', 'cmb2_post_search_ajax_metaboxes_example' );