Nuxy
Search…
10. Autocomplete
One of the most complicated fields and requires a post_type array field - to suggest options for the user.
1
'autocom' => array(
2
'type' => 'autocomplete',
3
'post_type' => array('post'),
4
'label' => esc_html__('Post to choose', 'masterstudy-lms-learning-management-system'),
5
),
Copied!
But you can add your custom filter to suggested options - stm_wpcfto_autocomplete_autocom where autocom is a key of a field. You should pass an array of items like this:
1
add_filter('stm_wpcfto_autocomplete_autocom', function ($r, $args) {
2
3
$r = array(
4
array(
5
'id' => 1,
6
'title' => 'Title 1',
7
'post_type' => '',
8
),
9
array(
10
'id' => 2,
11
'title' => 'Title 2',
12
'post_type' => '',
13
),
14
array(
15
'id' => 'fewfewbfhewvbfewjhvfewg',
16
'title' => 'Title 3 with rand -' . rand(),
17
'post_type' => '',
18
),
19
array(
20
'id' => 4,
21
'title' => 'Title 4 with rand -' . rand(),
22
'post_type' => '',
23
),
24
);
25
26
return $r;
27
28
}, 10, 2);
Copied!
If you need to limit added options you can add "limit" parameter to field
1
'limit' => 1
Copied!
Last modified 10mo ago
Copy link