Nuxy
  • Nuxy
  • Installation
  • Adding Page Options
  • Adding Post Options
  • Adding Taxonomy Options
  • Adding Frontend Options
  • Getting Fields
  • Adding to admin bar
  • Tabs
    • General tab parameters
    • Add submenu
  • Field parameters
  • Registering field
  • Fields dependency
  • Fields group
  • Field types
    • General field parameters
    • 1. Text
    • 2. Number
    • 3. Textarea
    • 4. Checkbox
    • 5. Select
    • 6. Radio
    • 7. Color
    • 8. Image
    • 9. Editor
    • 10. Autocomplete
    • 11. Datepicker
    • 12. Datepicker range
    • 13. Time
    • 14. Sortable
    • 15. Sortable multi input
    • 16. Gallery
    • 17. Repeater
    • 18. Range slider
    • 19. Image Select
    • 20. Button group
    • 21. Icon picker
    • 22. Ace Editor
    • 23. Spacings
    • 24. Link color
    • 25. Multi checkbox
    • 26. Color Gradient
    • 27. Textarea with hints
    • 28. Typography
    • 29. Multiselect
    • 30. Notification Message
    • 31. Button List
    • 32. Group Title with Preview && Icon
  • Download Nuxy
Powered by GitBook
On this page
  1. Field types

10. Autocomplete

Previous9. EditorNext11. Datepicker

Last updated 4 years ago

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