To address this sorting issue, you need to implement custom sorting logic within the loop that handles the display of posts. The solution involves the following steps:
- Fetch and Store Posts: Collect all the queried posts into an array. This allows you to manipulate and sort the posts before rendering them.
- Custom Sorting Function: Create a custom sorting function using
usort()
to sort posts by the custom taxonomy term first and then by post title. The sorting function needs to handle:- Primary Sort: By the custom taxonomy term using a predefined order.
- Secondary Sort: By the post title alphabetically within each taxonomy term.
- Display Sorted Posts: After sorting, use a loop to output the posts in the desired order.