• Resolved supadigital

    (@supadigital)


    Hi

    I have a pod called fsp_products. I also have another pod called product_thank_you_pa.

    The fsp_products post type has a relationship field linking to the product_thank_you_pa pod, and the related field is called fsp_product_thank_you_page_url.

    fsp_product_thank_you_page_url returns the TITLE of the related product_thank_you_pa.

    I need to get the permalink of the related post using the this TITLE field value.

    I have tried various code snippets from the documentation site without success.

    I would really love it so much if someone could assist with this. It seems the latest version of wordpress has changed some of the get functions and one is supposed to use wp_query now, but I am not clued up here. IF someone is able to provide a possible code snippet for the above, i would be massively appreciative.

    Thanks so much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    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

    Thread Starter supadigital

    (@supadigital)

    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>

    Plugin Author Jory Hogeveen

    (@keraweb)

    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

    Thread Starter supadigital

    (@supadigital)

    @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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting related post permalink value’ is closed to new replies.