forked from alexis-magina/cmb2-field-post-search-ajax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-field-setup.php
67 lines (62 loc) · 2.26 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
<?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' => __( 'Example Terms', 'cmb2' ),
'id' => 'cmb2_post_search_ajax_demo_multiple_terms',
'type' => 'post_search_ajax',
'desc' => __( '(Start typing term name)', '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(
'hide_empty' => false,
'taxonomy' => array( 'category' ) // post_tag, custom_terms
)
) );
}
add_action( 'cmb2_init', 'cmb2_post_search_ajax_metaboxes_example' );