This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I'm working on a music/events listing site with a few custom post types and custom fields provided by the CPT UI and Advanced Custom Fields plugins (though they can all be coded in, instead of using plugins). Right now, there are 3 custom post types:
- Show
- Venue
- Artist
Each "show" is just a post where you can select one venue and multiple artists via the ACF "Post Object" field-type.
On the homepage, I would like to organize the shows by date, then alphabetically by venue, so that all shows for any day are grouped together:
Ex:
Sat. Feb 8th:
venue 1
venue 2
Sun. Feb 9th:
venue 1
etc.
I've managed to get the sorting nearly working by adding a custom filter and including the following in the query args:
Filter:
function customorderby($orderby) {
return 'mt1.meta_value, mt2.meta_value ASC';
}
Query Args:
'meta_key' => 'show_date',
'meta_query' => array(
array(
'key' => 'show_date'
),
array(
'key' => 'venue'
)
)
That returns all of the posts organized by show_date, then the meta_value "venue".
My issue is, the data stored in the "venue" field is just the post ID for the related venue so, instead of sorting the venues alphabetically, it sorts them according to the INT value of their ID. What I need to do is return the post_title of the related post and sort by that string. So, for example:
'meta_key' => 'show_date',
'meta_query' => array(
array(
'key' => 'show_date'
),
array(
'key' => get_the_title('venue')
)
)
Is it possible to do something like what I'm describing? If not, my next solution is to run multiple queries:
- First, get a list of each day with a show according to show_date
- For each day that there is a show, query the posts and sort by the venue title (though, I might have the same problems as above doing that, since it's still just a post ID)
I would really prefer to figure out how to run one query and just sort it as needed, instead of having 60 queries on the homepage.
Has anyone done anything like this before or possibly know of a solution?
Subreddit
Post Details
- Posted
- 10 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Wordpress/c...