[Resolved] Views: ordering in a "per item" basis, in many to many relationship
This support ticket is created 2 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.
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.
I have 2 CPT: "Articles" and "Authors", with a "many to many" relationship.
The "Add new" and "Edit" forms in WP show an area "Author" where I can connect authors to the article.
I made a view "Authors of an article" to show the author(s) in the "Article" template. It´s working fine and shows the author or authors.
But sometimes, the order in which the authors are shown is important. Sometimes there´s a main author, and he/she usually goes first. So I´m trying to find a way to get the view show authors in a certain pre-defined order.
I´ve thought of adding a numeric field to the "Authors" CPT, but this would lead to an undesired behavior. In this example:
Article A
Author 1 (main)
Author 2
Article B
Author 2 (main)
Author 1
Ordering by the numeric field would lead to both articles showing the authors in the same order.
Article A
Author 1 (main)
Author 2
Article B
Author 1
Author 2 (main)
I´d like to set the order in a "per article" basis, but I´m not able to find a proper way to achieve this.
You need to store the custom field on the intermediate post type (a "relationship field") so that it is unique for the combination of the connected posts.
That way, instead of a particular author always appearing first, then can appear first when connected to one article and second when they are connected to another.
Then your View to display authors connected to an article should query the intermediate post type rather than the author post type, so that it can be ordered by the custom field stored on that post type. In the View output you want to display fields from the author post connected to the queried intermediate posts (e.g. the author post title), which is an option when specifying the source post when outputting fields.