WordPress request fiter order by related post's post_title
I have created two WordPresss custom post types (school, person). Each person is related to a school and the related school's post ID is stored in wp_postmeta under the person's post ID with meta_key = 'person-school-id' and meta_value = the related school's post ID.
I have added a person-type (Student, Teacher, etc. ) and the related School's name (by extracting the related school's post_title) to the Person WP edit.php list via WP manage_person_posts_columns and manage_person_posts_custom_column actions.
I have added filter capabilities for both person-type and person-school-id to the Person WP edit.php list via the WP restrict_manage_posts action.
And, I have added sort capabilities for the person-type to the Person WP edit.php list via the WP request filter using something like:
$vars = array_merge(
$vars
,array(
'meta_key' = 'person-type',
,'orderby' = 'meta_value'
)
);
So far, so good. All of this works as expected.
But, I also need to add sort capabilities for the related School's name (post_title). I could easily sort on the related Schools post ID (because that is what's stored in the person's wp_postmeta person-school-id meta_value field) by adding something like the following during the WP request filter:
$vars = array_merge(
$vars
,array(
'meta_key' = 'person-school-id',
,'orderby' = 'meta_value'
)
);
But I really need to order by the post_title (not post ID) of the post whose post ID is in the person's meta_value field for the person-school-id meta_key. Something like:
,'orderby' = 'select post_title from wp_posts where ID = ' . meta_value
Obviously, the above doesn't work.
All this to ask: How can I order by the post_title of a related post whose post ID is in a different post's wp_postmeta meta_value field while processing the WordPress request filter?
Topic request-filter post-meta wp-query custom-post-types Wordpress
Category Web