Post to a random Wordpress site, based on a defined list?

Is it a way to get a random value from a defined list?

I would like to be able to post randomly to one of my Wordpress sites. I can use the dynamic value to get that value (the site name/ connection name) into the Wordpress piece, but I haven’t figured out a way to get AP to pull one random value out of a predefined list.

Is that possible?

Hi @Preben ,

can you please specify from where you want to fetch the predefined list? If it is the static list you can use a code piece to get random value.


It can be from anywhere. Can be a list in AP, or a list in Google Sheets. It doesn’t matter to me, as long as I can define a list somewhere and pull a random value / item from it. :slightly_smiling_face:

@Preben, you can use a code piece.

export const code = async (inputs) => {
  const list = JSON.parse(inputs.list)
  const randomIndex = Math.floor(Math.random() * list.length);
  const randomElement = list[randomIndex];
  return randomElement;

Give the list as a parameter in step.

Let me know if it meets your requirements or not.


Thank you @kishanprmr . I think this will work, but I do not know how to tweak this so I can get it to work with names (and not just numbers).

I get an error when adding anything other than a number, and that is probably because I guess the code only will handle numbers?

With the help of ChatGPT I understood that I have to put the values in quotes. I first tried single quote ', but that didn’t work. Tried double quote ", and it worked.


Thanks @kishanprmr :blush:

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.