0

I have two custom posts type: course and teacher. A course can be related to one or more teachers. Relations are postmeta containing teacher post id.

I need to be able to filter courses list inside admin edit page looking for teacher post title containing the name of the teacher.

I'm trying with filters on posts_join and posts_where but I can proceed because every example teach how to join posts and postmetas but I need further query to full related posts.

2
  • 3
    using raw SQL or trying to modify the SQL generated is unnecessary and highly unusual, unless you're interacting with a 3rd party table writing SQL is usually a big warning sign that something has gone wrong in WP development, especially when you're trying to modify queries to WordPress core tables. The docs for WP_Query should contain the answer you're looking for, but keep in mind that post meta tables are not optimised for this, you'd have been better off storing your relation as a term in a taxonomy not a meta value, searching for posts via their meta values doesn't scale
    – Tom J Nowell
    Commented May 20 at 8:30
  • 1
    Seconding what Tom's saying, querying by postmeta is hideously slow and is absolutely not the right approach here. Taxonomies are indexed because they're designed for querying and filtering posts.
    – Chris Cox
    Commented May 21 at 13:26

0

Browse other questions tagged or ask your own question.