Skip Navigation

[Resolved] Sorting Child Output by Parent Field

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by marcL 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#617428

I have a set of classes and a set of people teaching those classes (both custom post types). I use a third post type, "instructors", to tie one or more people to a particular class. On a person's personal page, I now want to list the classes they teach.

I currently use a view over the available "instructors", which means I can easily filter using "Select posts that are children of the Post where this View is shown". In the loop I can also easily access the class title and year (using id='$class'), producing a nice list of classes a person is teaching. However, I need to sort these by the year of the particular class. Unfortunately, I can't seem to figure out how to do this, as all directly accessible fields are from the "instructor" post.

You can see a (trivial) example here: hidden link (looks sorted but fails on larger lists)

I alternatively tried to create a view over the available "classes", which I can then easily sort by the (custom) 'year' field of the class. However, I now loose the ability to filter by the person teaching the class.

Is there a way to sort the output of a view-loop based on a parent field?

Thanks!

#617735

Nigel
Supporter

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

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

Hi Marc.

No.

I have used the same analogy a few times recently, let me repeat it here.

With a playground of children you might tell all the children wearing hats to stand on the left, simple enough.

Your request sounds more like telling all the children whose parents have a combined income over €100k to stand on the left. But you don't know what the income of the parents of the children is, and guessing from the labels on their coats doesn't count.

This would work if the children came to school with a badge showing their parents' income.

In terms of querying the database that would be akin to custom table joins with SQL. Views queries are built on the native WP_Query class which means that such joins are not possible, and so you cannot filter or sort one thing by properties of another thing.

There is no workaround for this right now, other than changing how your data is structured.

However... as you may be aware, post relationships are undergoing a major overhaul currently—we will be releasing updated betas later today—and the data for recording relationships will in future be stored in custom tables, which means creating custom queries that will then allow for doing just what you want, sorting (or filtering) by properties of connected posts.

That particular feature is incomplete and won't be available in today's betas but is coming soon and will be in the final releases. I don't have a date for that, we are now talking about a timescale of weeks rather than months.

By the way, please note that you are posting in the Community Forum for users of the free Types plugin. As a Toolset customer you can and should post in the Technical Support forum which we prioritise and where you should receive speedier service.

#619125

Thanks for the quick reply, Nigel. I'll wait for that Beta to shape up then, hopefully this will be soon possible! Exciting!

The forum ‘Types Community Support’ is closed to new topics and replies.