I'm trying to sort a list posts by custom field associated with a taxonomy term. The purpose of this is to assign priority to the taxonomy term via a numerical value, so that the posts associated with the taxonomy term will be listed in accordance to that priority.
For context, I have a list of employees, each associated with a "Position" taxonomy term. There are levels of priority associated with each taxonomy term (ie. Principal Agent [priority level 1] > Receptionist [priority level 7]), so in the name of ease of access for the client, when they add or remove employees, any new or existing employees will be sorted based on the priority level of their position.
I'm not following any particular documentation, but I was trying to follow this support thread, but got lost in the explanation: https://toolset.com/forums/topic/sort-view-by-taxonomy
Here's a link to the page in question on my site: versteckter Link
From my understanding, Toolset doesn't have any out-of-the-box solutions for this. Is there a way we can adjust the solution found in the aforementioned support thread to support a custom field and only one sorting mechanism?
Hello,
You are right, Views is using wordpress class WP_query to query posts:
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
There isn't such an option to order the result by taxonomy
So as a workaround, you can use custom codes to setup a field to store the taxonomy value, then use this custom field as sortby parameter.
In the thread you mentioned above, that user is using a CRED form to create new post, so it is using action Toolset form hook "cred_save_data" to setup the custom field, see the codes here:
https://toolset.com/forums/topic/sort-view-by-taxonomy/page/2/#post-517595
If you need assistance to setup the similar custom PHP codes, please provide a test site with the same problem, also point out the problem page URL and form URL, and where I can edit your custom PHP codes, I need a live website to test and debug.
Thanks for the details, I can login your website, but I need more details:
There is only one Toolset post form in your website: Alert Submission
Are you going to use this form to update the "Alert" post custom field?
If it is, please provide the front-end URL, where I can test it?
Where one is the taxonomy field? which one is the custom field you want to update?
Thanks
That's not even related.
The client isn't going to be submitting a CRED form to add employees. They'll just be logging into the WordPress admin to do this.
What I need to do, is take the data from the "Employee" custom post type and sort the results in a view by their association to a "Position" taxonomy term. Each taxonomy term under "Position" has a custom term field that contains a numerical value that denotes its priority (ie. Principal Agent [priority level 1] has a greater priority over Reception [priority level 7]). The sorting does not need to be changed by the end user. The whole purpose of this is to parse the data out into a logical manner, grouping individuals by their job positions, and then sorting them by their position's priority.
Here are the views and layouts in question:
Layout for Locations: versteckter Link
Employee List View: versteckter Link
Positions Taxonomy Terms: versteckter Link
Thanks for the details, in your case, it does not need custom codes, it just needs a nested view, for example, I have done below modifications in your website:
1) Create a taxonomy view "Parent taxonomy view - Positions"
versteckter Link
query terms of taxonomy "Position", order by term field "priority", in the view's loop, display the child post view "Employees List View":
[wpv-taxonomy-title]:
[wpv-view name="employees-list-view"]
2) Edit the post post view "Employees List View", add a filter:
Select posts with taxonomy:
Positions set by the parent Taxonomy View
3) Edit the layout "Layout for Locations":
in section "Our Team", display the taxonomy view's shortcode "Parent taxonomy view - Positions" instead of post view:
[wpv-view name="parent-taxonomy-view-positions"]
Test it in front-end:
versteckter Link
Please check if it is what you want. thanks
More help:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
Views Inside Views – Display Nested Multidimensional Lists
It seems to be operating in a manner that works for what I need. Thank you so much for your help!