jQuery在Wordpress中自动填充

I'm using the following jQuery to auto-populate a text input field in a custom Wordpress search:

$(window).load(function(){
var availableTags = [
"Option A",
"Option B",
"Option C",
"Option D"
];
$( "#option_field" ).autocomplete({
  source: availableTags
});

This works great but I actually want the jQuery to pull in these results from some custom field options in my posts. I have a custom field in each post called 'Options'. Can I get the jQuery to pull in all the available options from this custom field then auto-populate my input field. For example if:

Post 1 has an 'Option' custom field entry of 'Chips'
Post 2 has an 'Option' custom field entry of 'Fish'
Post 3 has an 'Option' custom field entry of 'Cheese'
Post 4 has an 'Option' custom field entry of 'Cheese'
Post 5 has an 'Option' custom field entry of 'Fish' 

When typing in the search field, there will be three autopopulate options of Fish, Chips, Cheese.

Thanks for any pointers!

I think you should try this:

  1. First you need to get all 'Options' in to an array.
  2. Use array_unique() to remove equal values from array.
  3. Then, use jason_encode() to create an object
  4. Now you can use that object to populate the field.