Hi there,
I'm building a website for an art gallery. Artwork is a custom post type, and it contains a repeatable field group ("Artwork Detail Group"). The purpose of the repeatable field group is to associate multiple images with a single artwork.
Here's my question. I'd like to list the Artwork posts and sort them based on a field, Artwork Year, in the first instance of the repeatable field group for each Artwork. Is that possible using either Toolset's visual interface or in PHP?
Thank you!
Saul
PS. The website is currently password-protected. I can share the credentials upon request.
Dear Saul,
The repeatable field groups are based on one-to-many relationship, so each item of repeatable field group is also a single post.
Views is using WordPress class WP_Query to query posts, since the custom field "Artwork Year" is in repeatable field group, it is not in post type "Artwork", so you can not query "Artwork" posts and sort by custom field "Artwork Year" of other post type.
See WordPress document:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
Note that a ‘meta_key=keyname‘ must also be present
In your case, I suggest you try these:
1) Create a custom date field "first-artwork-year" in post type "Artwork"
2) Edit each "Artwork" post, setup the value in above date field "first-artwork-year"
3) Then you will be able to setup a post view:
- Query "Artwork" posts
- Sort by custom date field "first-artwork-year"
Luo,
Thank you for your response. This is the kind of work-around that I suspected I might need to resort to.
Before giving up, do you know if there is a way to order the results of a post query *after* the query has been run? Basically, I'm seeking the equivalent to the hook posts_orderby (https://developer.wordpress.org/reference/hooks/posts_orderby/) but post-query execution. (And that obviously doesn't change an ORDER BY clause, since the query has finished running.)
Thanks!
Saul
There isn't a way to order the results of a post query *after* the query has been run, WordPress is using MySQL query to query the database, the SQL query is running both the post query and order by at the same time. See MySQL document:
hidden link
Luo,
Thanks for your reply. I'll create the additional year field as you suggest.
Thanks!
Saul