[wordpress插件] Calculated fields for ACFACF的计算字段

wordpress 插件 文章 2020-03-15 16:30 579 0 全屏看文

AI助手支持GPT4.0

评分
100
描述

Adds a formula fields ot Advanced Custom Fields that allows you to perform simple math based on field values.

在“高级自定义字段”中添加公式字段,使您可以基于字段值执行简单的数学运算。

From version 1.1 calculations are done while editing fields in the admin screen.

从版本1.1开始,将在管理屏幕中编辑字段时进行计算。

When the post is saved, all fields are recalculated before being saved.

保存帖子后,所有字段都会在保存之前重新计算。

Requirements

要求

Calculated fields requires Advanced Custom Fields 5.0 or later and works with Pro as well as the standard version.

计算字段需要Advanced Custom Fields 5.0或更高版本,并且可以与Pro以及标准版本一起使用。

Formulas

公式

Calculated fields adds a new setting “Formula” to the the ACF field editor.

计算字段将新设置“公式”添加到ACF字段编辑器。

Formulas supports referring to other fields in the same Field group using the field name.

公式支持使用字段名称引用同一“字段”组中的其他字段。

If a formula is added to a sub field inside a repeater field, the name refers to another sub field in the same repeater.

如果将公式添加到转发器字段内的子字段,则该名称引用同一转发器中的另一个子字段。

A sub field inside a repeater field can also refer to a parent field using the “parent.”” prefix (new in version 1.1).

转发器字段中的子字段也可以使用“ parent。”前缀(1.1版中的新功能)引用父字段。

A formula can contain the basic mathematical operations: plus (+), minus (-), multiply (*), division (/) and power of (^).

一个公式可以包含一些基本的数学运算:加号​​(+),减号(-),乘号(*),除法(/)和(^)的幂。

Formulas can also contains functions like sin, cos, arcsin, log, ln, sqrt, abs.

公式还可以包含正弦,余弦,反正弦,对数,ln,sqrt,abs之类的函数。

Parentheses are supported.

支持括号。

If an expression can’t be evaluated due to invalid syntax or referring to undefined field names, it will silently return zero.

如果由于语法无效或引用未定义的字段名称而无法对表达式求值,则它将默默返回零。

Examples of valid expressions (note, no equal sign at the beginning):

有效表达式的示例(注意,开头没有等号):

    • fieldA * 2
    • fieldA * 2

    • fieldA * fieldB
    • fieldA * fieldB

    • abs(fieldA) * (2 + sqrt(fieldB))
    • abs(fieldA)*(2 + sqrt(fieldB))

    • amount * parent.price
    • 金额* parent.price

    Conditional operators (new in version 1.2.0)

    条件运算符(版本1.2.0中的新功能)

    An expression can also contain a conditional expression that will return either 0 or 1. The supported operators are:

    表达式也可以包含将返回0或1的条件表达式。支持的运算符为:

      • Equals (==) – Returns 1 when two values are equal, 0 otherwise
      • 等于(==)–当两个值相等时返回1,否则返回0

      • Not equals (!=) – Returns 1 when two values are not equal, 0 otherwise
      • 不等于(!=)–当两个值不相等时返回1,否则返回0

      • Greater than (>) – Returns 1 when the first operand is greater than the second, 0 otherwise
      • 大于(>)–当第一个操作数大于第二个操作数时返回1,否则返回0

      • Greater than or equal (>=) – Returns 1 when the first operand is greater than or equal to the second, 0 otherwise
      • 大于或等于(> =)–当第一个操作数大于或等于第二个操作数时返回1,否则返回0

      • Less than (<) – Returns 1 when the first operand is less than the second, 0 otherwise
      • 小于(<)–当第一个操作数小于第二个操作数时返回1,否则返回0。

      • Less than or equal (<=) – Returns 1 when the first operand is less than or equal to the second, 0 otherwise
      • 小于或等于(<=)–当第一个操作数小于或等于第二个操作数时返回1,否则返回0。

      Examples of valid expressions using conditional operators:

      使用条件运算符的有效表达式示例:

        • 10 == 10 (returns 1)
        • 10 == 10(返回1)

        • 10 == 2 (returns 0)
        • 10 == 2(返回0)

        • 10 > 2 (returns 1)
        • 10> 2(返回1)

        • 10 < 2 (returns 0)
        • 10 <2(返回0)

        • 10 <= 10 (returns 1)
        • 10 <= 10(返回1)

        Rounding functions (new in version 1.2.0)

        舍入功能(版本1.2.0中的新功能)

        Round a decimal value to the nearest integer.

        将十进制值四舍五入到最接近的整数。

        Supported functions are:

        支持的功能有:

          • round() – Uses standard mathematical rounding rules to round to nearest integer
          • round()–使用标准的数学舍入规则将其舍入到最接近的整数

          • ceil() – Rounds the value to the next higher integer
          • ceil()–将值四舍五入到下一个更大的整数

          • floor() – Rounds the value to the next lower integer
          • floor()-将值四舍五入到下一个较小的整数

          Examples of valid expressions using rounding functions:

          使用舍入函数的有效表达式示例:

            • round(10.2) (returns 10)
            • 回合(10.2)(返回10)

            • round(10.9) (returns 11)
            • 回合(10.9)(返回11)

            • round(10.888888 * 10) / 10 (returns 10.9)
            • 回合(10.888888 * 10)/ 10(返回10.9)

            • ceil(10.2) (returns 11)
            • ceil(10.2)(返回11)

            • floor(10.2) (returns 10)
            • 楼层(10.2)(返回10)

            Note that the round() function only takes one parameter and always round to an integer.

            请注意,round()函数仅采用一个参数,并且始终四舍五入为整数。

            If you need to round to a higher precision, multiply and divide as shown above.

            如果您需要四舍五入到更高的精度,请按上述所示乘以除法。

            Array functions for repeater fields

            转发器字段的数组函数

            If repeater fields are used, a calculated field in the parent field group can summarize a specific repeater sub fields using the aggregation functions sum, count, average, min or max.

            如果使用转发器字段,则父字段组中的计算字段可以使用聚合函数sum,count,平均值,min或max汇总特定的转发器子字段。

            For example, the expression: “Sum(orderlines.amount)”” will return the sum of all the “amount” fields in the repeater field “orderlines”.

            例如,表达式“ Sum(orderlines.amount)”将返回转发器字段“ orderlines”中所有“金额”字段的总和。

            The available array functions are:

            可用的数组函数是:

              • sum()
              • sum()

              • average()
              • average()

              • count()
              • count()

              • min()
              • min()

              • max()
              • max()

              Note that anything after the dot (.) in the aggregate expression is an expression in itself.

              请注意,聚合表达式中点(。)后面的任何内容本身就是一个表达式。

              It’s perfectly OK to write a formula like: “Sum(orderlines.price * amount)”.

              编写类似“ Sum(orderlines.price * amount)”的公式是完全可以的。

              This expression will walk over all lines in the “orderlines” repeater field, perform the calculation “price * amount” and return the sum of all lines.

              此表达式将遍历“订单行”转发器字段中的所有行,执行“价格*金额”计算并返回所有行的总和。

              Note that when working with aggregate functions, parentheses can not be used.

              请注意,在使用聚合函数时,不能使用括号。

              If you need to aggregate a more complex calculation, you should add an extra field in the repeater group and let the aggregate function work on this extra field.

              如果需要汇总更复杂的计算,则应在转发器组中添加一个额外的字段,并让汇总函数在此额外的字段上工作。

              Data type and calculation order

              数据类型和计算顺序

              Calculated fields works with the assumption that all fields are defined as numeric in the ACF editor.

              计算字段的前提是在ACF编辑器中将所有字段都定义为数字。

              Using a text field in a formula WILL PRODUCE UNPREDICTABLE RESULTS.

              在公式中使用文本字段将产生不可预测的结果。

              Calculations are made as the custom field is stored to the database.

              在将自定义字段存储到数据库时进行计算。

              To minimize the impact of performance, Calculated fields rely on field order.

              为了最大程度地降低性能影响,计算字段取决于字段顺序。

              A formula field can only refer to fields ordered BEFORE itself.

              公式字段只能引用在其本身之前排序的字段。

              A formula field that refers to a field ordered after it WILL PRODUCE UNPREDICTABLE RESULTS.

              公式字段,指的是在此字段后将产生不可预测的结果的顺序。

安装步骤

Minimum requirements

最低要求

    • PHP 7.3 or newer
    • PHP 7.3或更高版本

    Calculated fields will for ACF run on PHP 5.6 or newer, but we highly recommend following the official WordPress guidelines that currently recommends

    ACF的计算字段将在PHP 5.6或更高版本上运行,但我们强烈建议您遵循当前建议的官方 WordPress指南

    PHP 7.3.

    PHP 7.3。

    Install from within WordPress

    从WordPress中安装

      • Visit the plugins page within your dashboard and select ‘Add New’
      • 访问信息中心内的插件页面,然后选择“添加新内容”

      • Search for ‘Calculated Fields for ACF’
      • 搜索“ ACF的计算字段”

      • Click ‘Install’ and wait until the button caption changes to ‘Activate’
      • 点击“安装”,然后等待按钮标题变为“激活”

      • Click ‘Activate’
      • 点击“激活”

      Install manually

      手动安装

        • Download the zip file
        • 下载zip文件

        • Upload the calculated-fields-for-acf folder from the zip to the /wp-content/plugins/ directory on your server
        • 将acf计算域文件夹从zip上载到服务器上的/ wp-content / plugins /目录中

        • Navigate to the Plugins page in WordPress admin and locate the plugin

        • 导航到WordPress管理员中的“插件”页面,然后找到插件

          Click ‘Activate’

        • 点击“激活”

下载地址
https://downloads.wordpress.org/plugin/calculated-fields-for-acf.1.2.2.zip
-EOF-

AI助手支持GPT4.0