Navigation überspringen

[Gelöst] Custom ordering and viewimg a list of post types

This support ticket is created vor 4 Jahren, 11 Monaten. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Dieses Thema enthält 29 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von tobiasF-3 vor 4 Jahren, 11 Monaten.

Assistiert von: Nigel.

Author
Artikel
#1444013

I have a custom post type ‚projects‘ and a custom post type ‚contacts‘. Through a many-to-many relationship they are connected. The relationship has an intermediary post type with a select field for ‚crew-position‘, where users can select from a preset, descriptive name for the type of work the contact is doing on that project.

I have created a view ‚crew-list‘ that shows all contacts connected to a specific project on the project’s single page.

I would now like to CUSTOM order the order in which the contacts appear. Not alphabetcally, and not ser by the user himself by having to add a custom order number (like I have done at this moment). But rather I would like to preset the order by myself, so whenever people look at the crew-list in the frontend they see the list ordered in the same custom way.

Ideally, I then would like to create subtiltles in the list for ordering the crew-list into subthemes like client, agency and production. But that would be a nice add-on 🙂

What I have so far:
versteckter Link

Please use the same login as mentioned in my previous support tickets with the username: toolset@silvertree.ch

Thx for your help,
Tobi

#1444253

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi Tobi

The first question I have is about this: "I would like to preset the order by myself".

How and where would you intend to do this?

There are two parts to such custom ordering. The first is specifying the order, the second is outputting the posts in that order.

There is a seldom-used property of posts available—menu_order—which can be used to manually determine the order posts are displayed.

The problem is that specifying the order is tedious, it involves editing each post and manually applying a numeric value which is used to determine the order.

There are some plugins available which provide a nicer experience, where you can drag and drop the posts in the backend into the required order, such as https://wordpress.org/plugins/post-types-order/ or https://wordpress.org/plugins/simple-custom-post-order/

But it would likely require some effort to get Views to display the results respecting this order. I could help with that, but need clarification of what you expect.

#1444337

Hey Nigel, thx for the swift reply. Well, the simpler the solution the better 🙂 but that said: I think I will be defining the custom order more or less once, since it's quite straight forward in the movie business: the 'producer' comes first, then the 'director', then the 'DP' then the 'Editor' and so forth... On the other hand: it might very well be, that at a later date, we will add more positions to the crew list that might have to appear - let's say - in the first part of the list. If we then manually have to adjust dozens or hundreds of other crew positions to make it work then that's of course not ideal.

In the meantime I've had another idea on how this might be solved better?
- how about connecting the 'projects' and 'contacts' without an intermediary post
- then adding a hierarchical taxonomy
(f.ex. CLIENTS - Marketing Director, CLIENTS - CEO, AGENCY - Creative Director, AGENCY - Art Director, FILMPRODUCTION - Producer, FILMPRODUCTION - Director, etc)
- so when a contact is attached to a project the user also picks one or several taxonomies that match the crew position of that contact in the project
- then in a view the contacts would be sorted accoring to the order in the hierarchical taxonomy list?

Would that work? One advantage of this would be that I could add several positions to the same contact for a certain project. But then, how can I define a different crew position for a contact in another project?

Does this make sense? Or do you see even other better solutions for this? Would love your help in setting this up 🙂

Thx a lot
Tobi

#1444363

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Because someone could be a Director on one project and a DP on another project, etc., taxonomies won't work.

You really need to use the relationship fields (which are stored on the intermediate post type) and which are unique on each project, allowing the same contact to be different things on different projects.

But, taking a real world example, Rami Malek is an actor in Mr. Robot, but also a producer. And there are lots of producers.

So if you are displaying the Mr. Robot project you would maybe want to output the contacts something like...

Director
Sam Esmail
Producer
Kyle Bradstreet
Sam Esmail
John Lenic
Courtney Looney
Rami Malek
Christian Slater
Cast
Rami Malek
Christian Slater
Elliot Vilar
etc...

I don't think custom fields or taxonomies are going to be quite up to the job here.

I think your roles should really be a custom post type, that you also relate to projects-contacts.

Ideally you might use the existing intermediate post type in the projects-contacts relationship to connect to the role post type, but... it's a limitation of Toolset relationships that such intermediate post types can't be re-used in any way.

So, here's what I suggest.

You create the following post types:

Projects
Contacts
Roles
Credits

You then create 3 one-to-many relationships, each connecting to Credits, which will act as a kind of intermediate post type connecting Projects, Contacts, and Roles, like so:

Project Contacts Roles
    \     |     /
     \    |    /
      \   |   /
       Credits 

Conceptually a single Credit post would be for "Rami Malek as Producer in Mr. Robot", with another for "Rami Malek as Actor in Mr. Robot", etc.

Your workflow would likely be to publish a Credit post and connect an existing Project post, an existing Contact post, and an existing Role post, whether you did this from the front-end or the back-end.

To display a list of contacts, organised by role, on a single project page you would create a View to display roles (effectively the headers for each section), and in its output you would add a nested View which queried Credits with Query Filters for the related Project (set by the page where the View is shown) and for the related Contact (set by the parent View).

This would be returning the "intermediate" credit posts, but it is the contact names you want to display, so you would use the item attribute to specify the parent contact post as the source for the field(s) being output.

I guess you would want to control the order that, say, the cast members were output, so when you published a Credit post that could include a custom field with a numerical value for the order, and you could specify that field for ordering the above nested View.

So, not simple, but that's how I would envisage you being able to fulfill the requirements.

Have a think about that...

#1444425

Wow, Nigel, thx a lot for this thorough rundown and for understanding what I am looking for. Yeah, I guess I am more or less following 🙂 One question that came to mind:

- so in 'Roles' I would define the 'crew position' but also create a number field to pre-define the numerical order in which the credtis are shown?

I would like to have a pre-set order for all projects. Since users will add contacts to a project and define their roles independently from the front-end, I would like to make sure that they don't have to worry about the order of how the contacts are shown, but that this is pre-set by me.

Also : I would like the workflow to be:
- I am 'in' a project on the single view page
- I then would 'add a credit' (create the custom post type) and attach existing contacts and roles
So when adding a custom post type 'credit' it would be possible to make it automatically attach to the current project and still be able to attach the other two custom post types 'roles' and 'contacts', right?

Thx for your help!
T

#1444437

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Your "Roles" post type wouldn't need a custom field for crew-position, you would have something like 10-20 or whatever the number is of posts with titles such as "Director", "Executive Producer", "Producer", "Writer", "Actor" etc.

To output those in a predetermined order you could manually set the menu_order and then use that as the ordering option in the View, or you could use a plugin such as the ones I mentioned before so that you could manually drag and drop them into the preferred order. Any time you decided you needed a new Role you would publish it then adjust its order. (If you are worried about the number of plugins used on your site, you would only need to activate the plugin when you wanted to re-order the Role posts.)

I'm not sure how you would handle the ordering of contacts without explicitly setting an order when the Credit posts are created, so that Rami Malek appears as the first actor in Mr. Robot and Bohemian Rhapsody, but is lower down the list of Actors in No Time To Die. You could display them in something like alphabetic order, but otherwise you would need a custom field that explicitly specified the order for this particular credit.

Your workflow should be fine. You will have a form to publish credits which will include parent selectors for each of Project, Contact, and Role, and if you link to the form from a single project page the project can be pre-selected. See https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected

#1444443

Thx Nigel, that makes a lot of sense and it shows how detailed you are already thinking with me, because you are right: for several actors, there would need to be a custom order, since this will change per project. Thx for pointing this out and already thinking of this 🙂 I will try this out in the days to come and will get back to you if anything pops up, so let's please keep this open for the moment. Thx so much for pointing me in the right direction, am excited to try it out!
Cheers
T

#1444501

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

No problem, let me just set this as awaiting your reply so that it doesn't sit in my queue.

#1447193

Hey Nigel, I have managed to set up relationships and the form to add a credit with contacts and roles to a project on the project single view page. I am now struggling with setting up the view to see the project-specific credit list.

- I have set up a view to show all roles
- I have set up a 2nd view to show all credits and then query filter by the active project

I don't understand this part in your descripion above:
- 'a nested View which queried Credits with Query Filters ... and for the related Contact (set by the parent View).
I don't know where and how to apply this query filter.

Here's the project single page:
versteckter Link

Here's the parent view:
versteckter Link

And this would end up as the nested view:
versteckter Link

I am sorry, but somehow I cannot wrap my head around this yet 🙂

Cheers and thx
Tobi

#1449061

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Sorry for the delay getting back to you, I was tied up for much of the day.

I can't see the Views in the back-end you linked to, I need fresh site credentials, if I could get those from you please?

#1449131

Hey Nigel, I've tried to send you the credentials via the secure form, but now I don't see the info and the secure form does not open anymore when I click on the email. Did you receive them? If not, please send me another secure form request. Thx!
T

#1449381

ah now I see it, it was hidden as a private message, so I hope you have everything you need, otherwise just let me know, sorry for the confusion 🙂

#1450837

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

First, the good news.

Re-reading what I wrote above, I realise that the second query filter I described, which I said should be for related contacts, should of course have been for related roles (set by the parent View), it is the parent contact fields you will be outputting.

Now, the bad news.

Looking at your site to see how to implement it, I recalled that you cannot have more than one relationship query filter at a time in a View.

That completely blows a hole in the proposed solution, and I'm not sure if there is another solution.

Let me see if there is a way I can influence the inner View using custom code so that we can trick it to work as if two post relationship filters were possible.

This may take a little while...

#1450861

Yeah, that was exactly what I feared you would say 🙂 I realised that too... keeping my fingers crossed, also for maybe another approach...

#1451267

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

I've found an old code snippet that a colleague used that may help, but in testing it out I'm not seeing the same results they did, so I'm not sure if something has changed since they used it.

I need to check with them, but they are not working today, I'll need to see if I can get this working Monday morning after speaking to them or one of the developers.