Skip Navigation

[Resuelto] Displaying post relationship name

This support ticket is created hace 3 años, 1 mes. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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+01:00)

This topic contains 4 respuestas, has 2 mensajes.

Last updated by Jamal hace 3 años, 1 mes.

Assisted by: Jamal.

Autor
Mensajes
#1975677

Tell us what you are trying to do?
Display post relationship name in loops. Before it was working with the following code, but it suddenly stopped working and it's showing the product title instead of the author title (related custom post).

The code I use is:
[wpv-conditional if="( $(wpcf-varios-autores) gt '0' )" evaluate="false"]<h3 class="book-author-shop">[wpv-post-link id="[wpv-post-field name="_wpcf_belongs_autor_id"]"]</h3>[/wpv-conditional]
[wpv-conditional if="( $(wpcf-varios-autores) gt '0' )"]<h3 class="book-author-shop">VV.AA.</h3>[/wpv-conditional]

A conditional, if there are more than 1 posts related to the product, then it prints VV.AA. If not, it prints the name of the author.

Is there any documentation that you are following?
Yes, read some articles but still dont find the way.

Is there a similar example that we can see?
My website.

What is the link to your site?
lenguadetrapo.com

#1975871

Jamal
Supporter

Languages: Inglés (English ) Francés (Français )

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

Hello and thank you for contacting the Toolset support.

This code is using the old relationships from Toolset Types 2.x and it will no longer work for the recent versions. I am not sure how the relationship is set but it is more likely to be a one-to-many relationship.
Because you want to display two different values based on the number of related posts, I think, that the most straightforward way will require some custom code to check how many related posts are there. The custom code can use the toolset_get_related_posts from our relationship API. Read more about it here https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

If you are unsure how to implement this custom code, allow me temporary access to check how the relationship is set, and let me know where this code is used and I'll be happy to help. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1983587

Hello,

Sorry, the support ticket got closed, i was away these days. I'm ready to gove you full access to the site. Thanks.

#1983667

Jamal
Supporter

Languages: Inglés (English ) Francés (Français )

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

Your next reply will be private to let you share credentials safely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

Let me know if I can take a copy of your website in case I need to do more debugging on my local setup.

#1983867

Jamal
Supporter

Languages: Inglés (English ) Francés (Français )

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

When I first see the code below, I thought that the relationship is a one-to-many or one-to-one relationship

[wpv-post-link id="[wpv-post-field name="_wpcf_belongs_autor_id"]"]

It turns out to be a many-to-many relationship as you can see in this screenshot hidden link

To display a related post in a many-to-many relationship, we use a view of the related posts to the current post of the view, or to the current post in the loop. Then you can use the shortcodes inside the view without using the id attribute or the item attribute.

I built a content template and a view to give an example, but I can't preview a product or an autor using the content template because both custom post types use a Toolset layout, which takes precedence. I noticed that you already have a similar view in an autor layout. Check this screenshot hidden link
The view is hidden link

I hope this answers your question. Otherwise, please let me know where can I find the code you shared in your first message?

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