Skip Navigation

[Resolved] Sorting custom view query by intermediary post type's content (order number)

This support ticket is created 6 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 5 replies, has 2 voices.

Last updated by Luo Yang 6 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#619474
Screenshot 2018-02-25 15.21.27.jpg

I'm following your guide (How to set up post relationships using Toolset) to do exactly what the same thing as in the example - connecting a custom post type (songs) to another custom post type (albums), and assigning track numbers to the songs on the albums.
https://toolset.com/documentation/post-relationships/how-to-set-up-post-relationships-using-toolset/

I am able to create the CPTs, many-to-many relationships and the view, but I'm unable to sort the songs by the track number, which is a custom field within the intermediary post type.

I searched through the documentation, and found that one option could be to filter the query after it gets listed. How can I do that with Views? I've already tried adding another query filter, but I can't find any option that would allow ascending or descending sorting based on the track numbers.

If I select "Ordering" by the custom field of the intermediary post type, it shows the dropdown menu to select ascending/descending, but the third field, which says "As a number" is grayed out. So I wonder if my data is in correct format, or does it auto-detect the type of the field?

If I add another query filter after the "Select posts in the Songs on Albums relationship, that are related to the Post where this View is shown.", I can't find any options that would allow me to further sort the query based on the custom field of the intermediary CPT.

Is there another way to use the custom order, which is defined by the custom field (track number) in the many-to-many relationship intermediary post type? The type of the custom field is "number", which sounds like the perfect data type to define the order, but should I use something else?

Is there a better way to do this?

Link to a page where I display the view:
hidden link

On this page, the songs are in the right order just because the post-ID's are in the correct order - but I can't rely on that being the case with every song, and the songs have different tack numbers on collections, so I need this list to actually be sorted by the intermediary post type's custom field.

I expected to see:
Option to order by meta key, maybe? Something that lets me sort the view by the track number.

Instead, I got:
A few ways that sound like they're going to do what I want, but the selections I chose didn't show any results (no posts were found).

#619586

Dear Joona,

How do you setup the view?
You can create a view, querying posts of intermediary post type "tracks", and order by the field "tracks number":
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

In the view's loop, display it's parent songs post and albums post information:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

#620141
view-setup-songs-tracks.jpg

I tried setting up the view for the intermediary post type, but it doesn't find any posts that way.

I've attached a screenshot of the view setup.

Translations and explanations:

Julkaisun biisit = The songs of the release
Biisit = Songs (the post type of songs that I'm trying to list on the album post type (Julkaisu).
Biisit julkaisuilla = Songs on releases (this is the intermediary post type)
Julkaisu = Release (the post type I'm showing this view on)

#620321

I assume you have registered the custom fields "tracks number" into post type "Biisit julkaisuilla"(intermediary post type), but not into post type "Biisit".

In your screenshot, you are querying post type "Biisit", so you can only order the result by custom fields of post type "Biisit", you can not order the result by custom fields "tracks number" of other post type "Biisit julkaisuilla".

If you want order the result by custom fields "tracks number", you will need to setup the view to query the posts of post type "Biisit julkaisuilla"(intermediary post type).

#620442
Screenshot 2018-02-28 10.40.43.jpg
Screenshot 2018-02-28 10.47.16.jpg

Yes, I have only assigned the track number custom field to the intermediary post type. There is only one field (number) in that field group. Should there be more fields? And should the field group be assigned to more post types? I can't see the custom field group of the intermediary post type in the field groups editor in Toolset, so I suppose it cannot be assigned to anything else than the intermediary post type, nor edited outside of the relationships editor? Or should I create a new custom field group and then assign it to both post types (songs and the intermediary)?

When I'm editing the view, I get this message "This will filter out posts of the following types, because they are not parent of any other post type: Biisit julkaisuilla Intermediary Posts". So how can I set the intermediary post type as a parent of the other post type?

#620787

There are lots of questions in this thread, we can handle them one by one, for the first original question:
Something that lets me sort the view by the track number.
Please try as I mentioned above:
1) register the custom fields "tracks number" into post type "Biisit julkaisuilla"
2) setup the view to query the posts of post type "Biisit julkaisuilla"(intermediary post type), and order by custom fields "tracks number".

If the problem still persists, please try these:
1) deactivate other plugins and switch to wordpress default theme, and test again
2) If the problem still persists, please provide a database dump file (ZIP file) of your website in below private detail box, also point out the problem view URL, I need to test and debug it in my localhost, thanks

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