Skip Navigation

[Resolved] How to show other Child posts with the same Parent tags?

This support ticket is created 3 years 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/Karachi (GMT+05:00)

Author
Posts
#2027077

Tell us what you are trying to do?

I want to show other Child posts with the same Parent tags.

Here is the structure of my site. It is based on a one-many relationship.
(Parent) Career
(Child) Review

I want to display all Reviews that has the same Parent tag. So, the results could be for Reviews from multiple Careers.

Additional note: The View will be on a Review page.

Would this be possible with Toolset?

#2027173

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

query-filter-settings.png

Hi Stanley,

Thank you for contacting us and I'd be happy to assist.

This is possible and you'll create a view for Review posts, with a post-relationship query filter, to show only posts related to the parent "Career" post, whose ID is passed through the view's shortcode attribute "wpvrelatedto".
( screenshot attached )

After that, you'll be able to pass on the current "Review" post's parent "Career" post ID ( i.e. [wpv-post-id item='@career-review.parent'] ) in the view's shortcode used on the single "Review" page, like this:


[wpv-view name="view-to-show-related-reviews" wpvrelatedto="[wpv-post-id item='@career-review.parent']"]

Note: Please replace "view-to-show-related-reviews" and "career-review" with your actual view's slug and relationship slug, respectively.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2027369

Hey Waqar,
I'm not getting any results and this is my setting.

This shows a result.

[wpv-view name="career-review-related-posts"]

This doesn't.

[wpv-view name="career-review-related-posts" wpvrelatedto="[wpv-post-id item='@career-review.parent']"]

And just to confirm, this will show the Reviews from other Careers that share the same tag as the Review's Parent where the View is placed? Sorry, that might sound confusing.

#2028275

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

taxonomy-query-filter-settings.png

Thanks for writing back.

Sorry about the confusion, as I originally thought you only wanted to show those Review posts, which share the same parent Career post. But now, I realize that you need to get the tags (taxonomy terms) attached to the parent Career post and then show all the Review posts which share the same tags (taxonomy terms).

If that is correct, you can get the parent Career post's attached tag term's slug using the "wpv-post-taxonomy" shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-taxonomy


[wpv-post-taxonomy type='tag' format='slug' item='@career-review.parent']

Note: please change "tag" and "career-review" with the actual slugs of the target taxonomy and the relationship.

After that, just as suggested in the last message, you'll create a post view for Reviews posts, but this time add a taxonomy filter, that expects the target term slugs in the shortcode attribute.
( screenshot attached )

The view's shortcode with the shortcode attributes would look like this:


[wpv-view name="view-to-show-related-reviews" wpvposttag="[wpv-post-taxonomy type='tag' format='slug' item='@career-review.parent']"]

#2028521

"I realize that you need to get the tags (taxonomy terms) attached to the parent Career post and then show all the Review posts which share the same tags (taxonomy terms)."

You're almost right except we need to go one more level deeper.

I want to show all Review posts whose Parent posts have the same tags as the Review's Parent where the View is placed.

For example,
Review A - Parent post's tag is Fitness.
Review B - Parent post's tag is Business.
Review C - Parent post's tag is Health.
Review D - Parent post's tag is Fitness.
Review E - Parent post's tag is Fitness.

In this example, I want to display Review A, D, and E because their Parent post's tag is Fitness.

This tag worked in showing the slug tag of the parent post:

[wpv-post-taxonomy type="post_tag" format="slug" item="@career-review.parent"]

Here's my current code which shows no result:

[wpv-view name="career-review-related-posts" wpvposttag='[wpv-post-taxonomy type="post_tag" format="slug" item="@career-review.parent"]']

I have also tried this:

[wpv-view name="career-review-related-posts" wpvrelatedto="[wpv-post-id item='@career-review.parent']" wpvposttag='[wpv-post-taxonomy type="post_tag" format="slug" item="@career-review.parent"]']
#2028593

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please share temporary admin login details, so that I can see how this view is set up?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

#2029325

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the admin access.

You're correct and for this requirement, we'll have to go one more level deeper using nested views.

1. In a single Reviews template, you'll first need a parent view that gets the "Career" posts, where the tag slug value is passed through the shortcode attribute.

2. And, inside the loop of the parent view, you'll nest another view that shows the "Review" posts, related to the parent "Career" coming from the current loop item.

This means that the parent view will be using the "taxonomy filter" and the nested child view will be using the "relationship" filter.

I hope this makes it more clear.

#2029553

Sorry, I'm lost.

Here's what I did.
1. Parent view - hidden link (Get Career posts with tag slug value passed through shortcode)
2. Parent view loop with child view in the loop - hidden link (Nest Review posts via the Child view)
3. Child view - hidden link
4. Child view loop with the review content HTML - hidden link

Parent view ID: 546579
Child view ID: 546729

Then this is the code to show the Reviews:

[wpv-view name="career-review-related-posts" wpvposttag="[wpv-post-taxonomy type='tag' format='slug' item='@career-review.parent']"]
#2030641

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I've noticed that the views that you've set are correct, however, the taxonomy type slug, in this case, would be "post_tag" and not "tag".

Example:


[wpv-post-taxonomy type='post_tag' format='slug' item='@career-review.parent']

And likewise, the parent view's shortcode will become:


[wpv-view name="career-review-related-posts" wpvposttag="[wpv-post-taxonomy type='post_tag' format='slug' item='@career-review.parent']"]  

#2034029

Good news! The results are showing up but it is showing up in a weird way. Screenshot: hidden link

I'm using a two column format to show the careers but the View keeps showing that there aren't any results for the child view.

#2034031

Good news! The results are showing up but the View is showing up in a weird way.

I'm using the three column approach but it keeps saying my child View isn't display any results. Screenshot: hidden link

#2034977

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

That "no items found" message is expected when the parent view is cycling through a career post, which doesn't have any related child review.

To avoid that message, please make sure that no content is added between the "[wpv-no-items-found]....[/wpv-no-items-found]" tags, in the Loop editor section of both these views.

#2035343

There should be a cleaner way to do this. Even after I removed the content in the wpv-no-items-found]....[/wpv-no-items-found], there are still gaps in my content as shown in the screenshot.

hidden link
hidden link

#2035351

The no. of results shown is also very erratic.

I'm displaying 3 items in Child and 1 in Parent but the results shown can vary from 0, 6, 2, 3, 1, etc.

#2036405

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The variance in the number of results in expected, because the available data items based on the set criteria will vary with each review post.

The parent view "(CAREER REVIEW) Related Posts" is set to show '4' career posts with a certain tag. But it is possible that 4 careers posts with certain tags are not always available.

Then the child view "(CAREER REVIEW) Related Posts Child" is set to show '1' review post, related to the parent view's career post. But, it is possible that a certain career post has no related review post.

Summarizing it, based on these two views, you'll get a fixed number of results '4' ( 4 x 1 ), only in an ideal situation where:
a) there are 4 career posts available with a certain tag
And
b) Those 4 career posts also have at least 1 related review post attached to them, which are different than the currently viewed review post.
( the currently viewed review post will be excluded by the child view, because of the option "Don't include current page in query result" )

As for the gaps in the layout, you can share an example link for the review post where this can be seen and I'll be able to guide you accordingly.

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