Skip Navigation

[Resolved] Can I sort Child Posts by their Parent's Field?

This support ticket is created 7 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Shane 7 years ago.

Assisted by: Shane.

Author
Posts
#526209

Hi,
I have a loop of Child Posts, because the child post is an intermediate type used to connect 2 Parent CPT in a many to many relationship, the Child post itself doesn't contain any fields, and their names are generated randomly.

I would like to sort these child posts by one of their parent's field.

Is this possible?

Thanks

#526233

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ying,

Thank you for contacting our support forum.

Actually you wouldn't be able to sort the child posts by a parent field since the posts needs to be sorted by their own attributes.

What you can do is if the child view is in a parent view then you can sort the Parent view and the child view will display in the order in which the parents are being sorted.

You won't be able to sort the child view itself.

Thanks,
Shane

#526237

Thanks Shane,
The child is in a parent view, however the field I'm interested is from the other Parent.

ie, If I have an Art Show, and the Exhibit is my child CPT, I want to display all the Artworks (the other parent) by their alphabetical Title.
So I'm in the Artshow view, but I need to sort by Artwork.
Hope that's possible? As this would be quite essential for a fully working many to many relationship.

#526242

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ying,

Wordpress natively doesn't support cross CPT relationships so the relationship for a post is essentially done with 1 hidden custom field.

If the field is from another parent that the one you are using currently then it wouldn't be possible.

Thanks,
Shane

#526244

I'm a bit surprised with the lack of this. Do you have any suggestions for an alternative set up? I mean I can go through each of the intermediate type and rename them but that's a lot of work (hundreds of them) and defeats the purpose....

Surely it's quite common to need to list such as:

List the Artwork by a given artist that's being exhibited at this Art show
or
List the Songs that will be sung by an Artist at this Event

#526246

By the way I mean to list via some kinda of sorting, eg alphabetical.
I can already display the list, but not the sorting.

#526253

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ying,

The alternative I can see here is to place the child view in the Parent view that you wanted the children to be sorted by.

This is because the child posts doesn't have the fields themselves so the parent will need to be sorted by this field .

A view can only sort posts by it's attributes.

Thanks,
Shane

#526454

Hi Shane, thanks for the suggestion.
Could you give a little bit guidance on how to set this up? I'm still new to Toolset.
Much appreciated.

#527079

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ying,

No problem, we actually have a document on how to setup the view in view with a post parent relationship.

https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

Take a look at the section that says "User View with a Post View for a child"

Instead of using Post Author, you need to use Post Parent.

Then once you have done the view in a view setup you will need to sort the Parent view.

Thanks,
Shane

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