Site icon Hip-Hop Website Design and Development

How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?

My website is a daily deals and offers site. I promote many online stores with affiliate links.

I have created a php script to detect any merchant’s link (ex- Amazon) and convert it to my affiliate link.

Example – (Script Name: redirect.php)

If you go to – https://example.com/redirect.php?link=https%3A%2F%2Fwww.amazon.com%2F

It will land you to Amazon site with my affiliate id attached to the url.

My Requirement:-

I have a separate custom field called “rehub_offer_product_url” where I put the normal link to merchant (1 field, 1 link per post).

Now I want the codes which can automatically encode the url of this field and add this part – “https://example.com/redirect.php?link=” before the encoded url when the post is saved (or drafted or published) so that I can fully automate the process of making a normal link to my affiliate link.

It’s ok if I see the transformed url next time when I go to edit the post, it just needs to work for the first time when I create and save or publish the post so that I don’t need to do it manually.

P.S. Don’t forget to mention where I need to add the code!

Please help me to make this happen and you’ll be BLESSED. 🙂 🙂