Title: Autocomplete Fun
Last modified: August 21, 2016

---

# Autocomplete Fun

 *  [Jonah Brown](https://wordpress.org/support/users/fishbaitbytes/)
 * (@fishbaitbytes)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/autocomplete-fun/)
 * Trying to add an auto complete and it is not working
 * Here is what I have.
 * Just need some help on this
 *     ```
       function wp_ajax_nopriv_izwootsy_charity_autocomplete() {
       	if (strlen($_GET['q']) > 1) {
       		global $wpdb;
       		//$results = $wpdb->get_results("SELECT post_title FROM ".$wpdb->prefix."posts WHERE post_type='store-charity' AND post_title LIKE '%".esc_attr($_GET['q'])."%'");
   
       		global $posts;
   
       		$results = new WP_Query( 'post_type=store-charity&post_title='.esc_attr($_GET['q']) );
   
       		foreach($results as $result) {
       			print $result->post_title."\n";
       		}
       	}
       	exit;
       }
       ```
   
 * I want this to load up post results and prepare them for an autocomplete
 * Here is the JS
 *     ```
       jQuery(document).ready(function($) {
       	$("#charity").autocomplete('/wp-admin/admin-ajax.php?action=izwootsy-charity-autocomplete', {
       		width: 300,
       		multiple: false,
       		matchContains: true,
       		formatItem: function(data, i, n, value) {
       			return value;
       		},
       		formatResult: function(data, value) {
       			return value.split(".")[0];
       		}
       	});
   
       	function formatResult(row) {
       		return row[0].replace(/(<.+?>)/gi, '');
       	}
       });
       ```
   
 * For some reason it only shows the number 0. Any Ideas

The topic ‘Autocomplete Fun’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Jonah Brown](https://wordpress.org/support/users/fishbaitbytes/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/autocomplete-fun/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
