Nuxy
Search…
⌃K

10. Autocomplete

One of the most complicated fields and requires a post_type array field - to suggest options for the user.
'autocom' => array(
'type' => 'autocomplete',
'post_type' => array('post'),
'label' => esc_html__('Post to choose', 'masterstudy-lms-learning-management-system'),
),
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:
add_filter('stm_wpcfto_autocomplete_autocom', function ($r, $args) {
$r = array(
array(
'id' => 1,
'title' => 'Title 1',
'post_type' => '',
),
array(
'id' => 2,
'title' => 'Title 2',
'post_type' => '',
),
array(
'id' => 'fewfewbfhewvbfewjhvfewg',
'title' => 'Title 3 with rand -' . rand(),
'post_type' => '',
),
array(
'id' => 4,
'title' => 'Title 4 with rand -' . rand(),
'post_type' => '',
),
);
return $r;
}, 10, 2);
If you need to limit added options you can add "limit" parameter to field
'limit' => 1