Skip Navigation

[Resolved] 1 to many

This support ticket is created 2 years, 7 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 replies, has 2 voices.

Last updated by jillT 2 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#2338811

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?

#2338941

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

#2338953

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

#2338975

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

#2339025

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?

#2339089

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

#2339411

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)?

#2339709

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

#2339773

Unfortunately that does not work, it's merely a link to the product page it's on, not the 'parent' in the relationship.

#2339789

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

#2339867

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

#2340287

Thanks Shane. Yes, I had copied and pasted your first code which had the brackets 🙂
My issue is resolved now. Thank you!