Skip Navigation

[Resolved] Creating a calculated field from two custom fields

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by johannaH 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1253045

Tell us what you are trying to do? My site is going to curate mockup images etc from various vendors. I have become an affiliate for those vendors and I want to be able to automatically add the appropriate affiliate referral code to the source URL of image/product.

I plan to use a feed to post plugin to grab product feeds from the vendors - as described in this blog article - https://toolset.com/2019/03/import-content-post-typewp-rss-aggregator/

But I need to get my affiliate code built in.

So far I have installed the reference Listing Site - Travel Destinations and have created two new custom post types - Mockups and Vendors.

In Mockups I have a custom field Location which will contain the URL of the product on the vendor's site.

In Vendors I have a custom field for my affiliate ID

What I'd like to do is be able to put these two bits of information together and output them at the front end as a URL as the action of a button on my Mockups single item template so that if someone wants to buy a mockup, they click on this 'Buy Now' button (yet to be added) which sends them directly to the product on the vendor's site via my affiliate link

For instance hidden link

The URL for this product on the vendor site is hidden link

My Affiliate Code for DesignCuts is ?ref=stockmockups

So I'd like the URL for the action of the button to be hidden link

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link

#1253419

If Vendors and Mockups are related in a one-to-many post relationship, then you can use Types shortcodes to construct a link tag using the different pieces of information. When you insert a Types field shortcode in your Mockups template, you will see a popup window. The "Post selection" tab in the window will let you choose which post contains the custom field. This is where you can choose the parent Vendor post, for the affiliate field. The syntax will look like this:

<a href="[types field='your-url-field-slug' output='raw'][/types][types field='your-affiliate-slug' item='@relationship-slug.parent' output='raw'][/types]">[wpv-post-title]</a>

I can help you if you need assistance with this HTML.

#1254991

Thanks Christian.

It took me a while to figure out but eventually I was able to use a TB Button in my Content Template then add the code you provided as the URL for the button. That seemed to be the only Content Template block that would allow this to work. Custom HTML didn't and Shortcode didn't.

There are a few quirks still to sort out - particularly as the TB Button options don't have anything to do with styling the hover state and adding a div container and using custom CSS doesn't seem to want to work (though that had worked a treat when I had just a TB Field that I had manually put my affiliate URL into while I was waiting for your answer). Strange!

But the button now has the correct URL - pulling the remote product page URL from my Mockup post type and bolting my affiliate tracking code from my Vendor post type onto the end of it.