The formulas tool is very useful to make advanced editions on large amounts of posts.
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 between 10000 and 999999
- $random_letters$ = 6 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
- $random_date$ = Random date in format Y-m-d H:i:s starting from January 1st, 2 years ago until today. Available since CORE v2.14.1
- $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.
- $uuid$ = Generate a UUID. Available since CORE v18.104.22.168
- $uniqid$ = Generate a unique id. Available since CORE v22.214.171.124
- $current_value_lowercase$ = Current value as lowecase. Available since CORE v126.96.36.199
- $current_value_capitalize_each_word$ = Current value with the first letter of every word as uppercase (i.e. turn “my car” into “My Car”. Available since CORE v188.8.131.52
This is used only when you select the type of edit “custom formula” in the bulk edit tool. We have 2 formulas: REPLACE and MATH.
The syntaxis is the following (quotes required):
=REPLACE(""Replace this"", ""with this"")
=MATH("4 + 3 – $current_value$")
=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 product prices by 10%.
=MATH("$current_value$ + ( 0.234343898 * 0.1) – 29 / 28 "")
A complex math operation.
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
Wraps plain YouTube URLs with a shortcode
This is for advanced users. The replace formula accepts regular expressions (regex). You just need to prepend the “search” value with
=REPLACE(""[::regex::]/house(.+)/s"", ""Car $1"")
Please test your regular expressions before executing them, you can use this online tool.
- 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.