I have a one (CPT - Designs) to many (WC products) relationship.
I display the many (products) on the Design post
I want to have a link on the products to its Design post
Is this possible, or do I have to do it manually?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jill,
Thank you for getting in touch.
Are you referring to displaying the product's parent data ?
If so then you will perhaps need to create a custom template for your products and include its parent data there. It is essentially a manual process.
Thanks,
Shane
Hi Shane.
Thanks, but no.
On the product page I only want a link to the related page. ie "Find more products with this design" and that would link to the related 'design' post
I have a custom woocommerce single template and that link would be placed on that, to save time on adding it manually - which I may forget to do!!
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jill,
Since you have a custom woocommerce template then you can use this to add the link.
echo do_shortcode("[wpv-post-link item='@{relationship-slug}.parent']");
WHere you're going to replace {relationship-slug} with the actual slug of the relationship. This can be added directly to the php template that you're using.
Thanks,
Shane
I'm not using a php template as such, but template for products within toolset and using blocks, so how can I add the php you gave?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jill,
The method is essentially the same.
You will either user a single field block to add the URL and then select your parent post type like our tutorial below.
https://toolset.com/course-lesson/displaying-related-posts/#displaying-one-related-item-parent
OR you can simply use this shortcode.
[wpv-post-link item='@{relationship-slug}.parent']
Please let me know if this helps.
Thanks,
Shane
Thanks Shane
So, from what you have said, I take it that I can only have a link with the post title on.
I can't have specific wording with a link (as per my reply above #2338953)?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jill,
I was assuming that you only wanted the link itself , however you can specify the text with the link if you use this shortcode.
[wpv-post-url]
This will give you the raw URL for the page and you can construct your link like this.
<a href="[wpv-post-url item='@{relationship-slug}.parent']">My Link Text</a>
Thanks,
Shane
Unfortunately that does not work, it's merely a link to the product page it's on, not the 'parent' in the relationship.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jill,
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please where applicable please provide me with a link to an example page where I can see the issue.
I've enabled the private fields for your next response.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jill,
This should be fixed now. The issue was with the code.
This is what you had
<p><strong><a href="[wpv-post-url item='@{design-product}.parent']">See all products with this design</a></strong></p>
This is what it should've been.
<p><strong><a href="[wpv-post-url item='@design-product.parent']">See all products with this design</a></strong></p>
Notice i've removed the {} from the slug of the @design-product.parent slug.
Thanks,
Shane
Thanks Shane. Yes, I had copied and pasted your first code which had the brackets 🙂
My issue is resolved now. Thank you!