Skip Navigation

[Closed] Sort by custom taxonomy and order by specific order

This support ticket is created 3 years, 9 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)

Author
Posts
#1650903

We have a custom taxonomy: enhance, free, pro and regular

What we need to do is to sort the item inside the loop by the taxonomy and order it by this order pro, enhance, regular and free

Basically we just need is to display first the pro item in the loop and follow by enahance item, regular and all free item will be the last in the loop

here are the example:
hidden link

site link: hidden link

#1650947

Hello, one way you could do this without custom code is to add a custom number field to this custom taxonomy. Set the number for the pro term to be 1, the number for the enhance term to be 2, the number for the regular term to be 3, and the number for the free term to be 4. Now create a View of this taxonomy and order by the custom number field, ascending, as a number. In the View's loop, insert the term name for testing purposes, and display this View on your site somewhere. You should see the terms appear in the correct order.

Next, create a View of posts and add a Query Filter based on your custom taxonomy, set by the parent Taxonomy View. If you cannot see the Query Filter editor, scroll to the top right corner and click "Screen Options" to enable the Query Filter panel. In the loop, insert the post title for testing purposes. Now place this View in the loop of terms you created in the previous step I described. You have created a nested View structure, where the posts are sorted by term, ordered by the term custom field you created. You can go remove the taxonomy term name from the taxonomy View now if you'd like, and you can go into the post View and modify the loop to display whatever you want for each post.

Let me know if you have questions about the nested View approach, or if you need another solution for some specific reason.

#1651067

We created a term field to order the taxonomy

Problem is we cant sort it by the term fields if we are using the post types views
Sort by term fields are only available in taxonomy view

We also tried your suggestion pls take a look and let us know if we do it right
hidden link

The problem with that example is

1. the output is section by section or not inline
2. we need to have a pagination

PLS take note that we will be using it also in the archive pages:
hidden link

Thanks

#1652143

Still need assistance Thanks

#1653503

Hi, my schedule is a bit unusual in that do not work on Fridays, but instead I work Sundays. Sorry for the delay responding to your most recent comment.

Problem is we cant sort it by the term fields if we are using the post types views
Sort by term fields are only available in taxonomy view

Yes unforutnately this means you must use a nested View of posts, which leads to the other problems you mentioned:
1. the output is section by section or not inline
2. we need to have a pagination

So you can see that in the current system, unfortunately there is not a built-in solution that achieves exactly what you want using a taxonomy term to sort a View of posts. Since you also want a solution that will work in archives, I think the most practical alternative is to create a custom post field and sort your View of posts and archive of posts by this custom field instead of using a taxonomy term View and a nested post View. This solution will support pagination and will not break up the results into sections like before. However, it does require you to maintain duplicate data. You must use both the custom field and the taxonomy term to categorize each post.

If you're comfortable with writing custom PHP, I can show you some APIs that may be useful in automating this custom field value based on the term, or in automating the taxonomy term value based on the custom field.. Let me know if that's something you would like to discuss.

The topic ‘[Closed] Sort by custom taxonomy and order by specific order’ is closed to new replies.