[Résolu] Adding Fields to View Sorting Controls Sorting Options
This support ticket is created Il y a 3 années et 9 mois. 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 a View that displays content created by the currently logged in user and amongst the key information fields that are shown are the Title, Post Type and Post Status. I want the user to be able to filter their content by any of these three fields as there is an approval process behind submitted content so it would be useful for them to be able to see which of their posts are Awaiting Approval or Rejected etc.
Both Title and Post Type are selectable options from the Sorting Options panel in the Sorting Controls sidebar, but there is no option for Post Status I have gone back and watched the training video on the search feature and had a leaf through the documentation, but I cannot find any reference to how to add fields and options to this.
I dare say it's there and I've just missed it, but I've been searching for quite a while now with no luck. Can someone point me at the documentation required of provide an example of how to add Post Status to the Sorting Options for my view please?
I would have no issue sorting them programmatically, but that wouldn't provide the functionality required. I need to allow them to be sortable from the front end by the user. Surely there is a way to hook into the Sorting Options array and add post status?
Forcing it behind the scenes wouldn't serve any purpose as it needs to be at the users behest. You seem to have hooks for just about everything else, even some that aren't on the documentation such as:
I do not know if we had such a filter. But I am sure, that the hook will not be enough, it has to have the corresponding logic that will modify the view query to use this new sorting criterion.
I am approaching our 2nd Tier to get another opinion. I'll get back to you as soon as possible.
As a workaround, you can use a custom field that will also record the post status, and use that field for sorting. You can sync the value of that field by hooking to post_save. https://developer.wordpress.org/reference/hooks/save_post/
That's really disappointing as it seems like such an obvious field to be able to use.
I haven't had a chance to try and implement your workaround solution yet, but I'm not sure if I have missed a step in what you're suggesting. Obviously creating a field to track the post status isn't a big issue, but can you select custom fields in the OrderBy in the Sorting Controls?
The only thing I'm not really sure about is why I'd need to sync the value for front end sorting controls as the post status wouldn't be changing. This is where I feel like I've missed something.
I understand the frustration that you may felt about us not implement this sorting with post_status, but, as our developers have confirmed, it is not supported by WordPress, so we won't support it too.
can you select custom fields in the OrderBy in the Sorting Controls?
Yes, we can sort by custom fields. We can sort by strings and numbers.
The only thing I'm not really sure about is why I'd need to sync the value for front end sorting controls as the post status wouldn't be changing.
I suggested syncing the value of the custom field with the post_status just to avoid having to enter the value for the custom field on each post update(status change). If the status won't change, you won't need to implement any syncing.
I'll remain at your disposal. Let me know if you have any questions.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.