"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
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.
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
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.
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
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
I understand, feel free to open new tickets at any time if your client decides to move forward with name-based sorting.