Skip Navigation

[Resolved] Custom Ordering Relationship Posts in View

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to sort a view displaying child posts based on the parent custom field.

Solution:

This can only be done with a nested view setup where you have to perform the sorting from the parent view.

100% of people find this useful.

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

Last updated by Gavin 6 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1175937
screenshot3.png
screenshot2.png
screenshot1.png

Hello

I have successfully created many-to-many relationships and I can display the relationships using a View and order by Title, Post Date, etc.

However, I need the related posts in any relationship to be displayed in a specific order.

To do this I created a numerical custom field in the post relationship (see Screenshot 1) and entered a numerical value in this field. For post A it is 1 and for Post B it it is 2, and so on (see Screenshot 2).

I then set up the view to order the results based on this field (see Screenshot 3).

However, no posts are being displayed - i.e. no items are found by the view.

#1175961
#1176011

Shane
Supporter

Languages: English (English )

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

Hi Gavin,

Thank you for contacting our support forum.

Let me see how best I can assist you with this one.

The field that you want the view to be sorted by is on the intermediary CPT ?

Also this workaround is for an archive and wouldn't affect you if it just a regular view.

Please let me know.
Thanks
Shane

#1176019

Ah yes - it's not an archive view, just a regular view.

The field is on the intermediary CPT (although not entirely sure whether I set up the Relationships with an intermediary CPT or not as you had the option not to - and couldn't see why the option was there to not have an intermediary CPT?)

So.... because it's on the intermediary CPT and not on the post type itself, it can't find it to sort...?

#1176060

Ok - so when I try and simply display the field it is empty because it belongs to the intermediary CPT and not the CPT being sorted/filtered?

#1176065

Shane
Supporter

Languages: English (English )

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

Hi Gavin,

That is correct.

What you would need to do is to do is to create a nested view setup with the Intermediary CPT being the Parent view and the child view being the one you want to sort.

Then all you need to do is sort the Intermediary CPT view by the custom field and then add the Child view to that view and the child view should list out the content based on what the order of the Parent view is.

Also you will need to add the Post Parent query filter to the child view so that it will list out the correct children based on the Parent view.

Please let me know if this is clear.

Thanks,
Shane

#1176067

That makes sense... but the Intermediary view is not visible in the admin panel and I can't seem to go back into the existing Relationship and make it visible?

#1176070

ok - got it - enabled UI in Types. Will try...

#1176085

Ok... I'm having a problem getting it working.

I've set up a (parent) view that will display the intermediary CPT. This is sorted based on the custom field. Does this parent view need to also have this filter on it "Select posts whose parent is the page where the View is shown."?

Then the (child view) will display the CPTs. Will this also need to have the filter "Select posts whose parent is the page where the View is shown."?

#1176094

Shane
Supporter

Languages: English (English )

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

Hi Gavin,

You can edit the visibility settings of your CPT by going to Toolsets -> Post Types and from here you should be able to set your CPT to be shown, enable publicly_queryable setting and it should show up in views.

Thanks,
Shane

#1176096

Does my CPT need to be hierarchical?

#1176100

Shane
Supporter

Languages: English (English )

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

Hi Gavin,

No the CPT doesn't need to be Hierarchical.

All that is needed is for you to be able to query it with views. This way you can setup you Parent View.

The posts are already related internally.

#1176109
screenshot6.png
screenshot5.png
screenshot4.png

I'm still having problems.

In my example I have two CPTs - SOUNDS and SEQUENCES.

I have set up a many-to-many relationship between SOUNDS and SEQUENCES with an intermediary CPT called SOUNDS TO SEQUENCES.

I have set up a custom numerical field in the intermediary SOUNDS TO SEQUENCES so I can add a custom display order to each relationship.

So... for example SEQUENCE '002' is linked to SOUND '230' and SOUND '252'. I have edited the custom fields so the first SOUNDS TO SEQUENCES custom field is 1 and the second is 2. (see screenshot6)

On a single SEQUENCE page I want to display the SOUNDS in the order based on the custom field.

To do this...

I set up a parent view that displays SOUNDS to SEQUENCES . It is ordered by the custom field and also filtered by posts in any relationship with the post where the view is shown (i.e. a single SEQUENCE such as SEQUENCE '002'). (see screenshot4)

In the loop for the parent view I have nested child view that displays SOUNDS (it matters not what order) and filtered by selecting posts whose parent is the page where the View is shown. (see screenshot5).

However, I get this warning " This will filter out posts of the following types, because they are not hierarchical: Sounds"

What am I doing wrong?

Thanks.

#1176125

Shane
Supporter

Languages: English (English )

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

Hi Gavin,

From What I gather you want to place the Parent view on the Sounds cpt correct?

Also i missed your question earlier about "Select posts whose parent is the page where the View is shown."?"

This filter needs to be set on the Parent CPT.

Finally for your child post view it only needs to have the Child CPT selected which is Sequences.

Your Parent view should only have the intermediary CPT selected.

Please let me know if this clears this up for you.

Thanks,
Shane

#1176146
screenshot8.png
screenshot7.png

Hi Shane

Sorry if I've been confusing.

I want the Parent view placed on a page that displays a single SEQUENCE.

On that page I want to show the SOUNDS that are in a relationship with that SEQUENCE (in a custom order).

This is the parent view (to query the intermediary CPT)

See screenshot7

And this is the child view (to query SOUNDS)

See screenshot8

Thanks

Gavin