Hi there,
I'm building a portfolio website with Client and Project custom post types. (A Client can have one or more Projects associated with it, a one-to-many relationship.)
Let's pretend Client A has three Projects (X, Y, and Z) associated with it. When I am viewing Project X, I'd like to create a list of other projects (Y and Z) connected to Client A. And when I am viewing Project Y, I'd like to create a list of other projects (X and Z) connected to Client A. Does that make sense? How can I accomplish this?
Thank you!
Saul
Hello Saul and thank you for contacting Toolset support.
Yes, you can do this with a view. First, check the option to not include the current post, then add a query filter on the relationship to clients. And choose to get the related post from the current post where this view is shown.
If you encounter any issues implementing this, allow me temporary access to your website and I'll prepare an example for you. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Thank you for the credentials and the additional details.
The views on the content template are querying the repeatable field. So, I created another view on the classic editor.
On the classic editor we cannot set a query filter on the related post(Client) of the current user. So, I built the view and passed the client in a shortcode attribute. The client is pulled using the wpv-post-id shortcode an the item attribute.
The view needs two settings:
- Don't include current page in query result: Because we don't want to include the current Work post.
- A query filter on the parent post: We are passing it through a shortcode attribute.
Check this screenshot hidden link
The shortcode attribute that I created is named "client", we can pass the ID to it like this:
[wpv-view name="other-works-from-the-same-client" client="[wpv-post-id item="@client-work-1-m-relationship.parent"]"]
Notice how the item attribute is used to pass the parent post(Client) of the current post(Work). Read more about it here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
And the results seem correct to me. Check this screenshot hidden link
I hope this helps. Let me know if you have any questions.
This worked wonderfully. Thanks, Jamal!