Fields / Autocomplete

Read More: Fieldmanager_Autocomplete

Text fields that responds to user input with autocomplete suggestions (optionally via an ajax request).

This must include a datasource, which the autocomplete uses to search against.

  1. Example 1: Custom Datasource

    This is a the simplest possible example of using an autocomplete field. It uses a custom datasource and is not ajax-driven.

    $fm = new Fieldmanager_Autocomplete( array(
    	'name' => 'size',
    	'datasource'  => new Fieldmanager_Datasource( array(
    		'options' => array( 'Small', 'Medium', 'Large' ),
    	) ),
    ) );
    $fm->add_meta_box( 'Autocomplete Field', 'post' );
  2. Example 2: Post Datasource using Ajax Request

    This example also leverages the "show edit link" feature, which displays an "Edit" link next to the post title (only after the post is saved/loaded).

    $fm = new Fieldmanager_Autocomplete( array(
    	'name' => 'related_post',
    	'show_edit_link' => true,
    	'datasource' => new Fieldmanager_Datasource_Post( array(
    		'query_args' => array( 'post_type' => 'post' ),
    	) ),
    ) );
    $fm->add_meta_box( 'Related Post', 'post' );