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.