Skip Navigation

[Resolved] How to list sibling/brother posts on child post page

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

Problem:

Display a list of custom post type States sharing a parent custom post type State Group. The relationship, states-in-group, is one State Group to many States.

Solution:

Need to fix the post type relationship slug in Views shortcode, see details here:

https://toolset.com/forums/topic/how-to-list-sibling-brother-posts-on-child-post-page/#post-1122610

Relevant Documentation:

https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/

This support ticket is created 5 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Luo Yang 5 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1122319

I am attempting to follow info from https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/, https://toolset.com/forums/topic/display-sibling-pages-not-working/, and https://toolset.com/forums/topic/display-other-child-posts-on-child-page-with-many-to-many-relationship/ to display a list of custom post type States sharing a parent custom post type State Group. The relationship, states-in-group, is one State Group to many States.

I have created a view, states-children-of-state-group, displaying States, "Don't include current page in query result" unchecked, and a filter, "Select posts in a States in Group relationship that are a related to the current post in the loop." It's using a very basic loop.

LOOP:
[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<li>[wpv-post-body view_template="Loop item in Other States in Same State Group"]</li>
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

LOOP ITEM TEMPLATE:
[wpv-post-link]

Placing this view by shortcode in an actual State Group post displays the list of child State posts as expected.

Moving forward to set up the content templates to show this view with the context of the State Group parent on the State post, I have template state-group-parent:

[wpv-view name="state-posts-of-current-state-groups-post"]

...as well as template state-child-template:

[wpv-post-featured-image size="medium"]
[wpv-post-title]
<h4>Other states in the same group:</h4>
[wpv-post-body view_template="state-group-parent" item="@states-in-group.parent"]

Using this template on a State post displays the featured image, post title, and "Other states in the same group:" but nothing at all shows up from the view, not even "No items found."

I get the same result with the view filter set to "Select posts in a States in Group relationship that are related to the Post where this View is shown." Also when checking "Don't include current page in query result."

(As as additional stretch, I will want to also show cousin State posts which belong to a State Group which is a sibling to the current State post's parent, (aunt/uncle?), related through the same parent of the two State Group posts, a post type called Sets. I can save this for another ticket if necessary.)

Thanks for helping me wrap my brain around this going up the hierarchy and back down again.

#1122351

FYI, this is a dev installation (hidden link). If needed, the website credentials are here: https://toolset.com/forums/topic/needing-to-show-post-title-links-from-grandparent-and-beyond/#post-1115148, and you have my permission to test and debug in the website.

The relevant view: hidden link
The state-group-parent template: hidden link
The state-child-template: hidden link
The State post in which I've been testing it: hidden link

#1122610

Hello,

Thanks for the details, you are using post type relationship slug "state-in-group":
hidden link

I have done below modification in your website:
Edit the content template "State Child Template", change the content template shortcode from:

[wpv-post-body view_template="state-group-parent" item="@states-in-group.parent"]

To:

[wpv-post-body view_template="state-group-parent" item="@state-in-group.parent"]

Please test again, check if it is fixed.

#1122982

Nice! I was using the plural designation for the relationship rather than confirming the actual slug. (Need to be more diligent about that sort of thing!) Now it's all coming together. Thank you for your help, and sorry to bother you with such a trivial mistake!

#1123025

You are welcome

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