Skip Navigation

[Resolved] Sorting a View of posts by post author sorting by name instead of ID

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Christian Cox 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#602926

"When sorting a View of posts by post author, the sorting is actually based on the author's User ID, not name. Unfortunately there is not a good way to sort directly by author name. One workaround for this is to create a custom field on the post and include the author's name (last, first is probably the best format) and sort by that custom field. You could automate this with the WordPress save_post API."

Got this from Chris, but do not really understand how to proceed/.
Please advise,

Jos

#603043

Okay first, let's set up the custom field and get that sorting working. Then if it works well, I can help you automate it.
- Create a new Single Line custom field and assign it to the post type you want to show in your sortable View.
- Edit or create some of those posts and fill in the custom field with the Author's name in the format Last Name, First Name. Make sure you do this for multiple posts with different authors so we can test it's working as expected.
- Edit your View. Use the Loop Wizard to modify the loop so that your custom field is used instead of the post author.
- Check the View on the front-end of your site and confirm things are working as expected.

Let me know how it goes.

#603193

Well Chris, I did as you asked, although I left the post author field also in there. It is not sorting alphabetically. How can we achieve that and how can we automate it?
Second question: can we have a dropdown for 'Achter- en voornaam' like we have for 'Klant naam'?

I don't understand it, so I probably did everything wrong.

Jos

#603203

I did as you asked, although I left the post author field also in there. It is not sorting alphabetically.
One minor adjustment. Change this code:

<th>[wpv-heading name="achter-en-voornaam"]Achter- en voornaam[/wpv-heading]</th>

To this code:

<th>[wpv-heading name="types-field-achter-en-voornaam"]Achter- en voornaam[/wpv-heading]</th>

This should fix the sorting problem.

Second question: can we have a dropdown for 'Achter- en voornaam' like we have for 'Klant naam'?
Yes, change the filter and add type="select" to show a dropdown:

[wpv-control-postmeta field="wpcf-achter-en-voornaam" type="select" url_param="wpv-wpcf-achter-en-voornaam"]

Check and see if the filter is behaving correctly and then we can work on automation when you are satisfied with the filter functionality.

#603231

Okay Chris, it looks like it is slowly taking shape. I am still wondering how this should be automated. Is there a dropdown possible on the 'new order' form (Postform: Orderform)? There should be only orders for existing customers (people who are registered users).

But well, tell me first what to do next to get it going.

Thank you for your trouble educating me 😉

Jos

#603398

Hi Christian,
I haver decided not to proceed with the sorting on name. Various reasons, the main reason is that it takes too much time which the client probably doesn't want to pay for. Thank you very m much for your help untill now. I might come back to this in the future but I'll let you know by then.
Best regards,
Jos Vermeulen

#603455

I understand, feel free to open new tickets at any time if your client decides to move forward with name-based sorting.