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