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.