Skip Navigation

[Resolved] Ordering posts in pre-existing relationship with another posts

This support ticket is created 3 years, 10 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: Africa/Casablanca (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Ian Henderson 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1650359

I have two custom post types - publications and authors - connected by a many-many relationship.

I have a view listing authors of a publication, which appears on the publication page, but I need to order those authors based on the importance of their contribution. This previous help topic explains this perfectly, and I have tested it on a backup site: https://toolset.com/forums/topic/ordering-posts-in-a-relationship-with-another-post/

My problem is that my existing relationship did not have the option enabled: "Intermediary Post Type visible in WordPress admin menu".

Is there a way I can enable this to an existing relationship, so that I can add the custom numeric field "sort-order" to the relationship and order my existing authors. Without this option I can't create the view to query the intermediary posts type.

#1650459

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

I run a local test and I was able to display the intermediary post type by doing the following:
- Go to Toolset->Post Types.
- Locate the intermediary post type, hover over it and click on edit.
- Scroll down to the Options section and check the "show_ui" checkbox option. Check this screenshot hidden link
- Select under which menu the custom post type should appear. Check this screenshot hidden link

Custom fields can then be added from the custom post type edit screen or from Toolset->Custom Fields.

I hope this helps. Let me know your feedback.

#1655921

Hi Jamal

Thank you very much - it works. However, one issue - we have 2000 existing publications. If I switch the view over to the one using the intermediate post type (as described here https://toolset.com/forums/topic/ordering-posts-in-a-relationship-with-another-post/), and sort by the new relationship field 'author order' then the results of the view are blank if order is not applied. So if there is one author and I have not given a number in the order field, then the view returns no results. Same if I have multiple authors.

Is this because the View is 'breaking' if the sort order field is empty? I guess I could run some code to update them all to '1' to work around this?

#1656081

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Yes, you can indeed run a code snippet to set all the posts that do not have an order. But it will be a rather hard snippet to write. You may also use a combination of PHP and SQL code. Because you will need to look for all the posts that do not have an order, then enter an order for each post.

The easiest way would be to use Toolset views and forms, check the following scenario:
- Create a view that will query all intermediary posts that have an empty value for the order custom field.
- Create a page and put this view inside of it.
- Create an edit form that has an input field with default value 1, and the submit button.
- In the view, put and a link to this edit form inside the view.

Now you should have a list of all intermediary posts that have an empty order, and on each post, a form with the order input and the submit button. And you can manually update each post of the list. I am aware that this may be tedious for 2000 articles, but this is totally safe and does not require custom code, which, is actually out of the scope of this support forum.

I hope this helps. Let me know your feedback.

#1671877

Hi Jamal

I got around this by added the original view between the [wpv-no-items-found][/wpv-no-items-found] shortcodes and now it's working 100%. Thanks for the assistance!

best
Ian

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