Reward entity with a function on name change?

I'm currently using

{
  "criteria": {
    "renamed": {
      "trigger": "minecraft:player_interacted_with_entity",
      "conditions": {
        "player": {},
        "entity": {
          "type": "minecraft:pig"
        }
      }
    }
  },
  "rewards": {
    "function": "FUNCTION NAME"
  }
}

And then in the function I'm getting the closest pig with some filters but this can cause some problems when dealing with multiple entities. Is there a way to reward the pig that the player is interacting with with a function trigger executed as the pig?

Continue to help post