# 10. Autocomplete

**One of the most complicated fields and requires a post\_type array field - to suggest options for the user.**&#x20;

![](https://2194051268-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPJdxe1K-sVbh8qB1ld%2F-MQLWQqZEkxcT5Dh4kSM%2F-MQLwPSze-K5Hv9S9PdV%2Fimage.png?alt=media\&token=de91ee84-c1d8-4ff1-82fd-f34eb0f0895a)

![](https://2194051268-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPJdxe1K-sVbh8qB1ld%2F-MQLWQqZEkxcT5Dh4kSM%2F-MQLytNe9X7Zw7Bv9gVz%2Fimage.png?alt=media\&token=cf9804a8-eb9f-455c-b856-b0cad530ad91)

```
'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);
```

�

![](https://2194051268-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPJdxe1K-sVbh8qB1ld%2F-MQLWQqZEkxcT5Dh4kSM%2F-MQM3Ay7fbXhlGFWVi7z%2Fimage.png?alt=media\&token=cb6a45fc-7d4a-42a5-925e-ba1637ffd99e)

![](https://2194051268-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPJdxe1K-sVbh8qB1ld%2F-MQLWQqZEkxcT5Dh4kSM%2F-MQM4gCubeAFl52efoWE%2Fimage.png?alt=media\&token=4fcc1f70-c98c-45a9-a007-f7d81079e1aa)

If you need to limit added options you can add "limit" parameter to field

```
'limit' => 1
```

�
