How to replace multiple items with formula

I am still trying to come up with a way to only display the text of a post returned by wordpress rest api, instead of all the html, ads (which display a code, not an ad), and various character strings which represent special characters.

This formula works to remove one string:

REPLACE_ALL(STRIP_HTML_TAGS(data.wp_base1.content.rendered, true), ( " ", “”)

How can I list multiple strings in the section where I place the string I want replaced? I need to add all of the special character symbols and ad codes and pretty much everything as a hack or workaround because I cannot find anywhere how to get wordpress to return only text in the proper format. It is as if nobody has ever built a real mobile app with wordpress rest api, so I am trying to find a solution in appgyver.

Thanks for any help.


You might be able to simply use the REPLACE_ALL and use &.*?; as a property and another REPLACE_ALL with <script.*?</script> as the property to get rid of scripts, I’m not a 100% sure that will work. I have stumbled into a similar issue with wordpress content and solved it in the following way using javascript:

  • Add a javascript box to your logic flow where you will format the text

  • Set data.wp_base1.content.rendered as an input e.g. content to the javascript box

  • To get rid of code bits I added the following line (you can create as many of these as you’d like, just name the consts differently):

const toBeRemoved = new RegExp(% <the_code_I_wanted_to_get_rid_of> %, 'g');

Replace % with `
the ‘g’ makes it a global expression so it finds all instances of that code

  • To replace the codebits in your text content add the following line:

const result = inputs.content.replace(toBeRemoved, '')

  • To replace all other special characters, see this stackoverflow thread. You can string it along right after that previous line, so something like

const result = inputs.content.replace(toBeRemoved,"").replaceAll('&.*?;' , "")

  • Finally, add the final line to output the text:

return { result }

And now you can e.g. set the result to a page variable and display that in a text component :slight_smile:

1 Like

Thank you so much, I will try this! This si exciting because I have not even played with the javascript blocks yet! Thank you. Now I have an idea of what can be done.

1 Like