This might be more of a MySQL question, but since I'm in WordPress I thought I'd start here. Here's my query:

$persons = $wpdb->get_results(
        'SELECT id, post_name, post_title 
         FROM wp_term_relationships AS tr, wp_posts AS ps 
         LEFT JOIN wp_terms AS wt ON tr.term_taxonomy_id = wt.term_id

and here's the error that is returned:

WordPress database error: [Unknown column 'tr.term_taxonomy_id' in 'on clause']

We know that term_taxonomy_id is a column in the wp_term_relationships table so I'm not sure why the column is unknown unless there is something about the order of things. Thoughts?

  • You appear to be attempting to SELECT FROM two tables. This won't work. You need to join wp_term_relationships. Commented Dec 3, 2021 at 1:32

1 Answer 1


The issue was that the tr.term_taxomony_id is not a column in either of the two joined tables, but in another table referred to further on in the statement. Now it is obvious to me that there would have to be a common key between the two joined tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.