Skip Navigation

[Resolved] Display the text from a custom field of a parent CPT with a link to this post

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user wanted to create a link to a related post(parent) but the link text should come from a custom field.
This was not working on Blocks.

Solution:
Create an unassigned content template. And switch the editing mode to the classic editor and use a similar code to the following:

<a href="[wpv-post-url]">[types field='landnaam'][/types]</a>

Then use the content template inside the archive loop with a shortcode block using:

[wpv-post-body view_template="Landenlink" item="@bestemming-product.parent"]
This support ticket is created 3 years, 9 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by EdwinK1906 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1671279

Hi support,

I am trying to set up the output of my product archive. Within it I want to display the value of a custom text field from a parent CPT(bestemmingen). The displayed text must link to the parent post. It shows the the right value of the custom field but the link goes wrong. See link to "Sardinië". When i set it up with the shortcode " wpv-post-link" the link works fine. See second link "Rondreis Sardinie"

hidden link

I have used the following code.
<a href="[wpv-post-url item="@bestemming-product.parent"]">[types field='landnaam' item='@bestemming-product.parent'][/types]</a>

The permalink for products " rondreizen" and for the bestemming parent CPT it is "rondreis"

I think I am making a stupid mistake but cannot find out what it is. Can you help me out?

Thank you .

Kind regards
Edwin

#1672121

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Edwin and thank you for contacting the Toolset support.

The code you have added should work for a parent post in a One-to-Many relationship. You may also use an unassigned content template that will generate the link and put it inside of your code using the item attribute as you have done.

If it does not, we'll need to debug why. Please allow me temporary access to your website and let me check it closely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1673723

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Thank you Edwin for the access credentials.

It seems that the shortcodes break inside the "Fields & Text" block, probably because of switching from visual to HTML. I would suggest using a Classic block with the code that you have added to your first reply.

As you are building the archive template with blocks, I would rather suggest using a Toolset "Button" block, and configure it to pull the custom field and the URL from the related post. Use the first for the button text and the last for the button URL.
I created an example on your website, check how on this screenshot hidden link

The "Fields & Text" blocks are still there, I'll let you remove them.

I hope this helps. Let me know if I have missed something.

#1674771
customHTML.jpg

Hi Jamal,

I already noticed that the button function would work like that. You would expect that there was also such a function purely for text. A dynamic text combined with a dynamic URL. I suppose you could make the button transparent and make it look like a normal text link. But it does not seem to be the proper way to go.

What do you exactly mean with a Classic Block? I have added the code in classic HTML Block ( see attachtment).

I have also made a view in the classic editor ( for the bestemminge CPT) on my homepage with the follwing code:
<a href="[wpv-post-url]">[types field='landnaam'][/types]</a>

They both result in wrong URL.

Can you take a last look at it for a solution?

Thank you.

Kind regards

Edwin

#1674945

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Edwin,

I tried a Classic block but it did not work for it too. So I tried the unassigned content template. First I switched the editing mode for the content template "Landenlink" to the classic editor and I used the following code:

<a href="[wpv-post-url]">[types field='landnaam'][/types]</a>

Then I used the content template inside the archive loop with a shortcode block using:

[wpv-post-body view_template="Landenlink" item="@bestemming-product.parent"]

Check the result here hidden link

I hope this helps. Let me know your feedback.

#1675257

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.