Skip Navigation

[Resolved] Get the data related to parent of the parent

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

This topic contains 6 replies, has 3 voices.

Last updated by ericF-5 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2198855

Hello,

I have created 2 custom post types FAQ and Answers, here the FAQ is related to the product which in one to many relation ( One product to Many FAQ ) not Answers post types is related to FAQ with one to many relation ( One FAQ to Many Answers ), now what and count like number of the Answers which is related to the product. How to achieve this ?

Thank you.

#2199391

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Can I clarify your question before proceeding, please, it is not entirely clear.

Do I understand correctly that when displaying a product post you want to show how many answers are available for that product? (Answers being grandchild posts of products.)

If that were the case you would likely need to create a custom shortcode that used the relationship API (specifically the toolset_get_related_posts function) to get the child posts, to loop over those and then use the same function to get the child answers of those FAQ posts, sum them and return the total).

#2199631

You understand it right, Is there anyway that I directly get connected answers to product like direct connection between product and it's grand child avoiding the child.

#2200291

Thanks for writing back.

Based on what you've shared, the 3 level relationship structure can be simplified by using the following approach:

1. Post Types:
a). Products
b). FAQs

2. Relationships:
a). Products -> FAQs
A one-to-many post-relationship, where one 'Product' post can have many related 'FAQ' posts.

You can save the actual question text, as the title of the "FAQ" post and the answer for that question, in the post content/body of that "FAQ" post.

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

#2200295

??????

You taking this thread to another direction what I have asked and what you have answered does not add up please read the thread again and give solution accordingly.

#2200461

I shared an alternative structure, because, I thought you were looking for a solution where a direct connection between the "Products" and "Answers" could exist.

> Is there anyway that I directly get connected answers to product like direct connection
> between product and it's grand child avoiding the child."

I'm afraid, it not possible with your existing setup because "Products" are linked to "FAQs" and then "FAQs" are linked to "Answers".

As there is no direct connection between grand-parent "Products" and grand-child "Answers", it is not possible to skip/bypass the child "FAQs".

In your current setup, to get the number of answers indirectly connected to a product, you'll need a custom shortcode that uses the "toolset_get_related_posts" function to first get the related "FAQ" posts and then the related "Answers" posts, as Nigel proposed earlier:
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts )

#2201231

My issue is resolved now. Thank you!