Hi, there's not an easy way to sort a View of posts by assigned taxonomy term because it's possible to assign multiple terms from a taxonomy to the same post. In that case, sorting would be difficult to program. Instead, you could create a View of the taxonomy terms and sort that View by term title, then include a nested View of posts filtered by taxonomy term set by the current term in the loop. Place your View of taxonomy terms on the page instead of your View of posts. That would achieve something similar, though not quite as flexible (you would be limited to filtering by the outer term View instead of filtering by the inner post View, for example). To effectively sort a View of posts by this term but allow filtering by post fields, you would need to create a custom field in the post that contains that year value and filter/sort by that field. Custom code would be required to automatically copy a term into a custom field when a post is saved. Let me know if you have questions about that.
Thanks. I'm interested in the second part of your response but a bit confused. Is there a simple enough way to change the year-made taxonomy to a custom field and then sort by, say a "year-made" field on my views pages?
You could certainly create a new custom field that holds the year value and sort based on that custom field. However, you would not get the taxonomy-based archive feature that is automatically created for taxonomy terms in this case. If that's not a problem for you, then yes you would just create a new custom field and start tracking the year in this field instead of the custom taxonomy. You could delete the custom taxonomy in this case.
If you need the custom taxonomy archive, then the solution isn't as straightforward because you would have to manage the year in two places. The solution here would require manual intervention or custom code.
On the Products page on the back end of WordPress, I can sort by year. On the front end I built a custom search page where I can also filter by year (hidden link). So I'm still confused; is there not a simple way to sort by year on the various gallery pages that are on the front end? Thanks.
On the Products page on the back end of WordPress, I can sort by year.
I'm including a screenshot of the Products page on my WP backend for your reference. Are you referring to being able to sort by the date in the far right column, or do you have another column visible in your Products page? Is that column showing a custom field value from the new year field I recommended creating, or a value from the Year Made taxonomy you already described, or some other Year information I am not aware of? Have I misunderstood completely?
On the front end I built a custom search page where I can also filter by year (hidden link).
Okay this View seems to contain a filter based on the Year Made taxonomy you already described. Filtering a View of posts by taxonomy term is possible but it's a bit different than sorting by taxonomy term. If you're interested in the technical reason for this, note that Views and Blocks use the WP_Query class of WordPress to query posts. In the WordPress documentation for the WP_Query class you can read how ordering / order by parameters can include meta values (i.e. custom fields applied to the post) but taxonomy terms are not offered: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters. Since the WP_Query results cannot be ordered by taxonomy term, the View of posts cannot be ordered by taxonomy term. This is true even though the query can be filtered by taxonomy term as described in the same document (https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters).
So I'm still confused; is there not a simple way to sort by year on the various gallery pages that are on the front end?
Maybe, but could you please clarify for me what you mean by various gallery pages? I just navigated a bit on your site and I can see that the URL hidden link seems to be the Product post type archive (also known as the Shop page in WooCommerce). However, the URL hidden link does not seem to be the exact same content, and I'm not clear how this gallery page was created since I can only see the front-end of the site. Is this page automatically created by your theme? Did you create it manually as a custom Page containing a View, or a Divi post gallery module of some sort? If it's a View, then the simple sorting method is to use a custom field to hold the year made information, and to disregard the Year Made taxonomy as we previously discussed. On the other hand, if the results are shown using a Divi post gallery module of some kind, please share a screenshot of the page builder content from wp-admin so I can see more details.
If you have questions about galleries other than the Shop page and the gallery page URL I just mentioned, please share those URLs as well as information about how those pages are created in wp-admin. This will help me provide more information about the available sorting options. If that's all too complicated or feels overwhelming, let me know. I can try to log in to the site to get more detailed information.
Actually the gallery and shop pages aren't what I'm looking to fix. Sorry for not being clear. There are several galleries of artworks, each with their own Toolset View built on the same template and separated only by categories.
They are: hidden link hidden link hidden link hidden link hidden link hidden link hidden link
I would be happy to make you a temporary admin if it would be easier for you to poke around yourself.
Yes I think a temporary admin login would speed things up a bit. Thanks for offering. I'll include private reply fields here so you can share login details securely.
So I'm still confused; is there not a simple way to sort by year on the various gallery pages that are on the front end? On the Products page on the back end of WordPress, I can sort by year.
Okay the Year information here is from your custom taxonomy Year Made and it is indeed sortable in wp-admin. Unfortunately there is no simple way to apply the same sorting to a View on the front-end of the site. For a technical explanation, see more information here in the "Order by a Taxonomy" section: https://ieg.wnet.org/2015/11/a-guide-to-custom-wordpress-admin-columns/
I'm not really clear how all this works, and it's limited to use in the wp-admin area. The code would have to be refactored to work on the front-end instead, and to only be triggered when specific Views are being processed. So no, I don't see a simple way to achieve sorting by a custom taxonomy term on the front-end of the site. The simplest way is as I explained earlier - use a custom field to store the Year value instead of, or in addition to, the Year Made taxonomy term.
I see a lot of repetition in your gallery Views, and I'd like to take the opportunity to show you something that can save you time. Instead of creating all these different Views that use basically the same loop code, the same loop template code , the same sorting and pagination, but use only a different Query Filter taxonomy term value, I encourage you to check out this article describing how to pass arguments to Views: https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/
Basically you would just create one View for all Products and change the Query Filter to respond to a shortcode attribute (see shortcode-attribute.png). Then when you insert the View in each Page using the Divi builder, you can include a different term slug in the shortcode attribute like this:
You can see how this might speed up your development and maintenance processes. If you have questions about that, feel free to open a ticket and we can discuss in more detail.
Thanks for the tip on passing arguments to Views. I'll definitely set things up that way in the future.
As for my original question, I'm going to look into quickish ways to set up a custom field to store the year value, so if I have any questions about that I may get back to you when I tackle it next week.