• Resolved alanjacobs

    (@alanjacobs)


    Hi,
    I’d like to set a trigger “WP User Meta XXXXX gets updated with Meta Value”.
    But the Meta Value of the field needs to be a partial match as it ends with a year value, YYYY, which I don’t need in this case.

    e.g. Meta Value = My Value 2022

    So how can I get the trigger to match on the “My Value” part and NOT the year part. So any value that starts “My Value” will trigger?

    Cheers
    Alan

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Ruben Garcia

    (@rubengc)

    Hi @alanjacobs

    Actually the trigger ” User meta gets updated” only works with static meta keys and not dynamic keys

    But something you can perform is to use the AutomatorWP filters (https://automatorwp.com/docs/getting-started/filters/) to see if the meta key matches with the meta condition you want

    Here is an example about how to set up this automation, the trick is to set the “User meta gets updated” to “any meta” and place a filter in the actions sections to make the action only get run if the filter condition is meet.

    In the example I setup this condition to make that the action “Send an email to the user” only runs if the meta key “starts with” “my_value_” (showing you where the meta key tag is in the tags dropdown):

    View post on imgur.com

    Hope it helps!

    Thread Starter alanjacobs

    (@alanjacobs)

    Hi Ruben,
    Many thanks for the advice. I’ve been trying it but still seem to have some issues.

    I set up the Trigger as you suggest. My only change was that I added multiple actions, each with their own but identical filter. ( to remove multiple Roles and then add a final role )

    When I run this I am seeing in the logs that the filter is saying that it did not match so the Action is not performed.

    I use Ultimate Member and its User Profile ( so not the WP profile ). I have a number of custom fields added to this profile and can access them using your user_meta.

    Now as an Admin I edit a users profile and change the custom field of that user and save the profile.
    The logs now show the automation was triggered but despite the field being updated the filters are comparing against the old value and not the newly updated one – hence no surprise they say no match.

    So a few points from all this:
    When I as an admin update a users profile – does the automation run under my id or the users profile that I am editing? ( The logs seem to indicate it is the user but I’m not sure )
    Possibly this is also related to another of my questions about delayed triggers. In that case a user buys a Renewal product and a physical product and his order is only marked Completed ( which completes the trigger ) by an Admin. So again I wonder if the automation is running against the wrong userid?

    When creating the Actions it would be great if we could copy an existing action and/or filter to save having to enter identical ones repeatedly.
    Alternatively could a filter be made to apply to a group of actions rather than just one?

    Sorry for the lengthy post.
    Cheers
    Alan

    Plugin Author Ruben Garcia

    (@rubengc)

    Hi @alanjacobs

    I would be more than happy to ask all your questions:

    When I as an admin update a users profile – does the automation run under my id or the users profile that I am editing?
    The automation runs over the user who gets its meta updated.

    As you can see, the trigger is “User meta gets updated” which means that AutomatorWP is checking when a meta of a user gets updated, working on the user who gets its meta updated, not the one (commonly an admin) who updated this meta.

    When creating the Actions it would be great if we could copy an existing action and/or filter to save having to enter identical ones repeatedly.

    I’m sorry but actually there is no way to display actions or filters, is possible to clone an entire automation, but not actions or filters, that’s something we have already in our roadmap.

    Alternatively could a filter be made to apply to a group of actions rather than just one?

    Every filter just apply over the action is placed, to apply it in different actions you may need to add the same filter to every action you want to apply it

    Hope it helps!

    Thread Starter alanjacobs

    (@alanjacobs)

    Thanks for the quick reply.

    So today I started my local development server and immediately the Automation ran without me doing anything.
    From the logs it ran against about 100 users out of 500 actual users.

    The Automation did actually work as hoped in that if the users profile custom field was set to the correct value then the actions fired correctly. But why to all those users?

    I suspect this is due to the Trigger setting. By setting Key to Any then any profile that gets updated will trigger – this is very likely as there are numerous hidden fields in the user meta that are updated by the system at its own whim.

    Perhaps refining the Trigger to check a specific key rather than ANY would help?

    Cheers
    Alan

    Thread Starter alanjacobs

    (@alanjacobs)

    To answer my own question: Yes setting the Trigger to the specific key that I am updating works perfectly.

    Now only the single user that I update has the automation run against it and all the actions work as hoped.

    I’ll do some more testing but looks ok at the moment!

    Cheers
    Alan

    Plugin Author Ruben Garcia

    (@rubengc)

    Great @alanjacobs

    Hope you are enjoying AutomatorWP ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Setting a trigger using a partial match for a field value’ is closed to new replies.