The formulas tool is very useful to make advanced editions on large amounts of posts.

Syntaxis

We have 2 formulas: REPLACE and MATH.

The syntaxis is the following (quotes required):
=REPLACE(""Replace this"", ""with this"")
=MATH("4 + 3 – $current_value$")

Placeholders

As you can see in the math formula, we can use placeholders for variable information. We have the following placeholders available:

  • $current_value$ = the current value of the field
  • $random_number$ = a random number
  • $random_letters$ = random letters
  • $current_timestamp$ = current timestamp
  • $current_time_friendly$ = current time using the format set in WordPress general options.
  • $current_date$ = Current date in the format: d-m-Y
  • $column_key$ = Other field of the same post. Change “column_key” for the actual column key. For example. $post_title$ , $post_content$ , $post_status$ , $my_custom_field$, etc.

Examples:

  • =REPLACE(""bad word"", ""good word"")
    Replace one word or phrase with another.
  • =REPLACE(""$current_value$"", ""$current_value<br/>Thank you for reading my post!"")
    Add a message at the end of the post. It can be plain text or html.
  • =REPLACE(""$current_value$"", ""Welcome to my site!<br/>$current_value$"")
    Add a message at the beginning of the post. It can be plain text or html.
  • =REPLACE(""<img"", ""Do you like the image below? Share it!<br/><img"")
    Add a message above the post images asking the user to share the image. It can be plain text or html.
  • =MATH("$current_value$ + 10")
    Increase the prices of the products by $ 10.
  • =MATH("$current_value$ * 1.1 "")
    Increase products prices by 10%.
  • =MATH("$current_value$ + ( 0.234343898 * 0.1) – 29 / 28 "")
    A complex math operation.
  • =REPLACE(""$current_value$"", ""$_regular_price$"")
    Applying the formula to the sale price field, you can copy the value of the regular price into the sale price field.
  • =REPLACE(""$current_value$"", ""Posts published by $author$ on $date$"")
    Applying the formula to the “category” field, you can create categories combining other fields.
  • =REPLACE(""[::regex::]/^( +)(.+)( +)$/s"", ""$2"")
    Removes the spaces at the beginning and end of the values. For example, remove trailing spaces from the post content or prices

Regular expressions

This is for advanced users. The replace formula accepts regular expressions (regex). You just need to prepend the “search” value with [::regex::]

Example:

=REPLACE(""[::regex::]/house(.+)/s"", ""Car $1"")

Please test your regular expressions before executing them, you can use this online tool.

Notes

  • The math formula must be used only on numeric columns. For example, products prices. If you use it on text fields, like post titles, you will get errors because it will try to convert the text to a number.
  • The math formula works with numeric fields with computer format, not human format. For example, 100000.00 is allowed, but 1,000,000.89 is not allowed (the commas aren’t allowed, just decimals with a dot).
  • The replace formula accepts HTML but only safe/simple tags and attributes like links, paragraphs, images. For example, script tags will be removed.
  • If you use a text that contains html with the “style” attribute, the replace formula might remove the last semicolon from the css, making the search term not match.
  • If you use a text that contains html with attributes using a single quote, i.e. class=’test’, the replace formula might remove the attribute. Use double quotes to avoid this.
  • The “formulas” tool is very powerful and it must be used carefully. You MUST backup your database before executing formulas, if you enter the wrong formula you can mess up your posts data. Use it at your OWN RISK. We are not responsible for any data loss or disruption in your business caused by this plugin.
Close Menu