Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I load regular post tags as values for autocomplete field? What I have now is pretermined values like this:

var data = {items: [
{value: "1", name: "Siemens"},
{value: "2", name: "Phillips"},
{value: "3", name: "Whirlpool"},
{value: "4", name: "LG"}
};
$("#input_1_3").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name"});

I'm using Drew Wilson's Autocomplete plugin found at: http://code.drewwilson.com/entry/autosuggest-jquery-plugin. Any help would be most apreciated.

share|improve this question

1 Answer 1

up vote 0 down vote accepted
if(isset($_GET['get_tags'])):
  $output = array();
  foreach(get_terms('post_tag') as $key => $term):
    // filter by $_GET['q'] here if you need to,
    // for eg. if(strpos($term->name, $_GET['q']) !== false)...
    $output[$key]['value'] = $key;
    $output[$key]['name'] = $term->name;
  endforeach;

  header("Content-type: application/json");
  echo json_encode($output);
  die();
endif;

in this case your js would be something like:

$("#input_1_3").autoSuggest(
    "http://yoursite.com/?get_tags=1",
    {selectedItemProp: "name", searchObjProps: "name"});
share|improve this answer
    
Where exactly the if(isset($_GET['get_tags'])): snippet goes, because i haven't been able to get it to work? The autocomplete itself works with your code, it just doesen't get the tags as values. –  Andrew Feb 17 '11 at 11:30
    
in your theme functions, or a plugin.. –  onetrickpony Feb 17 '11 at 14:12
    
Now I know what the problem is: The autocomplete won't suggest tags without any posts assigned to them. Any ideas how to show the "empty" tags? Other than that your code clearly works, so thank you very, very much! –  Andrew Feb 17 '11 at 14:24
    
point your browser to http://yoursite.com/?get_tags=1. All tags you see there should also shown by the AC plugin. If not, you might need to filter them by $_GET['q'] (ie. get only the tags that contain the characters entered by the user) –  onetrickpony Feb 17 '11 at 14:49
    
Great, thank you very much. I got everyhting in order now. Much respect! –  Andrew Feb 17 '11 at 19:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.