So I have quite a complicated Toolset conditional output setup and copied it in multiple templates. I realised using a code snippet for a shortcode probably makes a lot more sense and then using IF statements in PHP.
I am fine with all this, however the conditional output is based on a posts custom field.
In the PHP code snippet, how can I get this Toolset custom fields value? Do I need to pass it in a Shortcode parameter? Or can I simply pull it using the Post ID?
E.g.
`if ($wpcf-affiliate-network == "C7" || $wpcf-affiliate-network == "kantar" ) {
echo "Result here, the Post ID is".get_the_ID();
}`
$wpcf-affiliate-network being a Toolset custom field belonging to whatever Post ID is being loaded on the page where this shortcut is being used. However I don't know how to get wpcf-affiliate-network's value.
But for some reason the output is the word "Array"? I am guessing since its a select box its not just storing the name but more than that? How can I just get the name selected?
Thank you for getting in touch.
The get_post_meta() function can be used when retrieving values from simple custom fields like "single line" and "multi line" however when using more complex fields such as checkboxes then you will need to use types_render_field( )
That worked perfectly thanks Shane! I have my shortcode working now.
Is there a way to hook this on to a field automatically? So my shortcode snippet always gets added whenever field "affiliate-network" is used.
Basically I am trying to add some tracking info on to the end of all links. With the old views this was simple because I could add my shortcode on to the end of where I am inserting the URL in HTML. However for sites I am using the block editor not sure how I could do this?
I guess I would recode the buttons in text and fields but would be better to keep using the block editor and also having it do it automatically makes more sense instead of always having to remember to use the shortcode.
You can still do this in the block editor but you would need to use the classic block and construct your links manually.
Meaning you will have your url like this.
<a href='myurl?param=[shortcode]'>My Link</a>
In classic views this is how you would do it but you can still achieve the same by adding the classic editor block to your view and then construct your link.