Hi @supadigital
A relationship is always related to the object itself, not a param/prop of this object.
Assuming you are using magic tags in our templates you can use the permalink property: {@relationship_field.permalink}
More info: https://docs.pods.io/displaying-pods/magic-tags/
Cheers, Jory
Hi @keraweb
I am actually needing to use the relationship field within a javascript code snippet and it seems magic tags don’t work in scripts?
Basically, what I am trying to do is get the permalink of the related pod by inserting the title of the that pod into the code snippet.
So when setting up an fsp_product, there is a relationship field that returns the title of a related pod post (product_thank_you_pa). I then insert that title into javascript snippet in order to get the permalink of that post and attach it to a variable in javascript which i then use later in the snippet for a redirect.
I have tried various snippets (I’m not too knowledgeable in coding, but rather using chaptgpt for snippets) but nothing works thus far. Any assistance would be appreciated. If its out of support scope, i understand. Thanks.
Below is one example of a snippet i used, but this returned an error: Uncaught ReferenceError: Pods is not defined
<script>
document.addEventListener("DOMContentLoaded", function() {
// Get the selected "product_thank_you_pa" title from the related field
var selectedTitle = Pods.getField('fsp_product', 'fsp_product_thank_you_page_url').find('option:selected').text();
// Find the corresponding "product_thank_you_pa" by title
var productThankYouPa = Pods.data.product_thank_you_pa.find(function(item) {
return item.title === selectedTitle; });
// Set the "url" variable to the fsp_product_thank_you_page_url of the selected "product_thank_you_pa"
var url = productThankYouPa.fsp_product_thank_you_page_url;
// Use the "url" variable as needed
console.log(url); });
</script>
Hi @supadigital
Magic tags are PHP only and do not work in JS. Where did you get the snippet from? It doesn’t really look like anything from the Pods codebase.
There are some methods available in PodsDFV (window.PodsDFV.getField() for example). This is all considered advanced usage meant for dev’s. Using AI for snippits is unlikely for solve this for you.
Cheers, Jory
@keraweb
Thanks so much for the feedback. I managed to do a workaround on this and forgot to close this ticket, apologies. Thanks though for your assistance, very much appreciated!