Skip Navigation

[Resolved] Question about displaying related posts (but not the one currently being viewed)

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

Problem:
The user would like to display a list of posts related to a parent post on the same relationship.

Solution:
The user is using the legacy editor. Check the detailed answer here https://toolset.com/forums/topic/question-about-displaying-related-posts-but-not-the-one-currently-being-viewed/#post-2198223

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

This support ticket is created 2 years, 6 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 3 replies, has 2 voices.

Last updated by saulB-3 2 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2197223

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

#2197571

Jamal
Supporter

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

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

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

#2198223

Jamal
Supporter

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

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

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.

#2198377

This worked wonderfully. Thanks, Jamal!

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