Skip Navigation

[Resolved] Query fields of related posts

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

Last updated by Max 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#920277

Max

I have such a structure.
1. Fights (parent)
2. Fighters (child)
3. Relationship fights-fighters (many to many)

The post type "Fight" has a select field "method" (with values: knockout, submission, judging ...).

My question (I want to make sure that today it is impossible).
When I ask for an intermediate post type "fights-fighters", can I query the "method" field of the related fight?

Now I solved the problem by moving the "method" field to an intermediate post type "fights-fighters". But it's wrong to duplicate the data ... Now you need to fill in method for each fighter, but you want to do it once - for "Fight".

Here is what I managed to find on this topic:
https://toolset.com/forums/topic/how-to-use-repeatable-field-as-filter/

I'm going to import a lot of data, so I want to do everything right. Can I leave the "method" field in the post type "Fights" with the hope that soon the query filter for the fields of the related posts will be available?

In the future I want to display data about the fighter "the number of wins by knockout" for example and so on ..
Thank you

#920620

Hello,

I assume you are going to setup a view to query the "fights-fighters" posts. and filter by custom field "method" of other post type "Fight".

If it is, the answer is no, there isn't such a built-in feature within Views plugin, and I don't think this feature will be available soon, and there isn't ETA for it.

As a workaround, when you query the "fights-fighters" posts, in the Views loop you can get he related "Fight" post information and it's custom field "method" field value
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/
Use it in the wpv-conditional shortcode, check if the custom field value is the specific value, and display the item in view's loop.
More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#922024

Max

Hi Luo
Yes you are right. At this stage I decided to avoid this problem.
Thank you.

Let's return to the related posts.
https://toolset.com/forums/topic/sorting-child-output-by-parent-field/#post-617735
Nigel said that with the help of the new m-m relationship it will become possible to sort and query related posts. Can you say (roughly) when this will be done?

#922290

I am not sure when will it be done, but there is a plan to implement it, I guess it might be months.

#922362

Max

Thanks I got it.
Will these queries from related posts to the database be slower? Will this be an additional layer of queries?

#922376

No, it should not produce the performance problem, but you can still feedback if there is any problem. Please create new thread for the new question, that will help other users to find the answers.

#922381

Max

Thank you