Skip Navigation

[Resolved] Displaying child posts on each other's sidebars

This support ticket is created 5 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 12 replies, has 2 voices.

Last updated by Christian Cox 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1230282

I am trying to display the post names of siblings in a series of post types on their own sidebars. I thought I had it solved, but it's telling me no items found.

Effectively, I would like to post a list of entries for a post type related to a parent.

e.g: All entries marked as related to the post named "Final Fantasy" in the "Game" post type, that are then in the "Journal" post type.

#1230285

My issue is resolved now. Thank you!

#1230289

Solution turned out bunk. Still need assistance please.

#1230617

Okay it sounds like you have a post relationship between Games and Journals. On the single Journal page, you want to display all the sibling Journal posts. Is that correct? If so, then you can use a View of Journal posts filtered by this Post Relationship, where the parent post is set by a shortcode attribute "wpvrelatedto". The corresponding View shortcode looks something like this with a hard-coded parent ID:

[wpv-view name="Your Filtered View of Journals" wpvrelatedto="12345"]

Next you want to pass the current Journal's parent post ID into the View instead of 12345. The current Journal's parent post ID can be retrieved using the wpv-post-id shortcode like this:

[wpv-post-id item='@game-journal.parent']

If you use the Fields and Views button to insert the post ID shortcode, you can then use the Post Selection tab in the popup to choose a related post. The proper syntax for the shortcode will be generated automatically by the system. Finally, combine these two shortcodes like this:

[wpv-view name="Your Filtered View of Journals" wpvrelatedto="[wpv-post-id item='@game-journal.parent']"]
#1230982

So, my concern is having to use the hardcoded ID. We have a number of editors and I'd like to make it more automatic than that. Is there no way to just display a list of journal posts in the series that have the specific game as the Game-Journal relationship?

As in, it reads it sort of as "If episodic review's Game is _______, then echo in sidebar of post" logic?

#1231066

So, my concern is having to use the hardcoded ID.
You don't, the hardcoded ID in step 1 was used to illustrate how things fit together. The rest of the explanation shows you how to make this ID dynamic based on the current post using a combination of shortcodes.

#1231078

Ah, I see, sorry I missed that phrasing.

I think I'm still doing something wrong. I've created a View for the related journals and assigned it to the post-type of said journals. I've told its template to just print the post name with its link.

Then I've created a content template for said journal post-type that prints the body of the journal text, and beneath it should print the list of related journal posts, as defined in the game-to-journal relationship (one-to-many). I've also used the shortcode you gave me, substituting the appropriate slugs. It prints nothing.

Is there a way I could give you access so maybe you could show me what I'm doing wrong?

#1231087

Sure, please provide login credentials in the private reply fields here and let me know where to find this View on the front-end of your site. I'll take a closer look and see what's going on.

#1231090

As a note on that, the view in question for listing is named Related Episodic Reviews - SIDEBAR, and the post-type Content Template is Episodic Reviews.

#1231095
Screen Shot 2019-04-15 at 1.44.21 PM.png

Okay I changed two things:
1. The post relationship slug is actually "game-with-episodic-content", not "game-journal" so I made the appropriate update in the view shortcode:

[wpv-view name="related-episodic-reviews-sidebar" wpvrelatedto="[wpv-post-id item='@game-with-episodic-content.parent']"]

2. The View "Related Episodic Reviews - SIDEBAR" has a post relationship Query Filter. That filter is set to display posts related to the post where this View is shown. That's not quite right, because the Episodic Reviews aren't related to one another directly. They're each related to the same Game, so it's an indirect relationship. I've updated the filter to respond to a shortcode attribute wpvrelatedto (see the screenshot), and now the filter is reading the parent Game ID from the wpv-post-id shortcode.

#1231100

Thank you so much Christian, that was amazing!

#1231101

Sorry, I just needed one more piece of assistance in case I need to call this in PHP. How would I wrap this tag using the do_shortcode command?

<?php do_shortcode("[wpv-view name='related-episodic-reviews-sidebar' wpvrelatedto='[wpv-post-id item="@game-with-episodic-content.parent"]']"); ?>

returns as an error.

#1231103

Don't use do_shortcode to render a View, use the Views API render_view: https://toolset.com/documentation/programmer-reference/views-api/#render_view

If you have questions about that, feel free to open a separate ticket and we can discuss in more detail.