dttl3933 2015-06-23 21:33
浏览 46

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!

  • 写回答

1条回答 默认 最新

  • dpm91915 2015-06-24 04:09
    关注

    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.
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示