简体   繁体   English

将一个字段的值复制到另一个(ACF-高级自定义字段)Wordpress

[英]Copy value for one field to another (ACF - advanced custom fields) Wordpress

I'm using ACF - Advanced custom fields and I have two fields Price text (text field) and Price Filter (number).I want to achieve that when I enter a value in one field (Price Text field ) to automatically copy into another field (Price Filter field). 我正在使用ACF-高级自定义字段,我有两个字段Price文本(文本字段)和Price过滤器(数字)。当我在一个字段(Price Text field)中输入值以自动复制到另一个字段时,我想实现这一点字段(价格过滤器字段)。 Does anyone have an idea how to do this? 有谁知道如何做到这一点? 在此处输入图片说明

Advanced custom fields will add ids to your input fields in the edit screen. 高级自定义字段会将ID添加到编辑屏幕中的输入字段。 You can leverage that and create a small jQuery script that copies the content of your first field to your secondary field while you type. 您可以利用它并创建一个小的jQuery脚本,在键入时将第一个字段的内容复制到第二个字段。 Something like this should work: 这样的事情应该起作用:

add_action('admin_footer', function () {
?>
<script type="text/javascript">
  $('#acf-field_5c19647c09c56').on('keyup', e => {
    $('#acf-field_5c19648909c57').val(parseFloat(e.target.value));
  })
</script>
<?php
});

Remember to replace acf-field_5c19647c09c56 with the id of your Price Text field and acf-field_5c19648909c57 with the id of your Price Filter field. 请记住,将acf-field_5c19647c09c56替换为您的价格文本字段的ID,并将acf-field_5c19648909c57替换为您的价格过滤器字段的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM