Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

4
Is it possible to lookup the associated post_title in meta_query when only the post ID is stored in meta_value?
Author Summary
elspic is in Idaho
Post Body

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?

Author
User Suspended
Account Strength
0%
Suspended 4 months ago
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
594
Link Karma
1,548
Comment Karma
23,499
Profile updated: 5 days ago
Posts updated: 9 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 years ago