Skip Navigation

[Resuelto] Show related post

This support ticket is created hace 2 años. 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.

This topic contains 2 respuestas, has 2 mensajes.

Last updated by Fabian hace 2 años.

Assigned support staff: Waqar.

Autor
Mensajes
#1792827

Hi.

I have a website in which I have created several types of custom posts.
On the one hand I have teams and on the other players.
I have created a one-to-many relationship

Now when I show a player's post, I want to show related players, but from the same team. I think I have tried all possible ways, but I can't, beyond showing other players in general, but not from the same team. What I need is that somehow, the system detects which team belongs that player that is being shown and shows other players of the same team to which it belongs.

Something escapes me, but I don't know what it is. Can you help me?

I don't use the new method through blocks, because I don't use them. I need the solution for the usual system.

Greetings

#1793753

Waqar
Supporter

Languages: Inglés (English )

Timezone: Asia/Karachi (GMT+05:00)

view-settings.png

Hi,

Thank you for contacting us and I'd be happy to assist.

To achieve this you can follow these steps:

1. You'll create a new post view, for example, "View to show related Players from the same Team" and set it to show the "Players" posts.

2. In the view's settings, check the option "Don't include the current page in query result" so that the current player is not included in the results and also add a post-relationship filter, linked to a shortcode attribute "wpvrelatedto", as shown in the attached screenshot.

This view will allow you to show all players, related to a specific team whose ID has been passed through the view's shortcode attribute.

3. In your content template for the "Players" post, you can get the ID of the related "Team" post, using the item attribute, in the "wpv-post-id" shortcode:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/ )

Example:


[wpv-post-id item='@team-player.parent']

Note: Please replace "team-player" with the actual post-relationship slug used on your website.

4. Combining this with the view's shortcode, you'll insert the view's shortcode in the content template for the "Players" post, like this:


[wpv-view name="view-to-show-related-players-from-the-same-team" wpvrelatedto="[wpv-post-id item='@team-player.parent']"]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1794073

Hello Waqar. Well, this was the only option that I didn't try, because I don't quite understand it in the manuals. But it has already become perfectly clear to me and it opens up many new possibilities for me. It is a very powerful solution.

It worked perfectly and I have fixed the problem.

You have been a great help and I appreciate your time and the solution you have given me.

Greetings