I have the following tables (only pertinent info included for brevity and clarity)
Table Name: wp_term_relationships
object_id term_taxonomy_id 1266 1341 1266 452 1266 449
Tabloe Name: wp_term_taxonomy
term_taxonomy_id term_id 1341 1342 452 453 449 450
Table Name: wp_terms
term_id name slug 1342 792 792 453 396 396 450 394 394
I have a list of the wp_term "names" and I want to get a list of the object_ids (only unique ones) from wp_term_relationships
So, my list will be something like: 394, 396, 988, 666 And I would like it to return (based on the above data): 1266 (i.e. Using term_id from wp_terms to get term_taxonomy_id from wp_term_taxonomy and then finally using that value in wp_term_relationships to get the object_id)
I am quite new to mySQL and have been reading/experimenting with it all day and can't seem to get it quite right.
SELECT $wpdb->term_relationships.object_id FROM $wpdb->term_relationships LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id LEFT JOIN $wpdb->terms ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE name IN (394, 396, 988, 666) GROUP BY $wpdb->term_relationships.term_taxonomy_id ORDER BY $wpdb->term_relationships.term_taxonomy_id DESC
I wondered if someone could maybe cast an experienced eye over it and help me see where I'm going wrong?
Thank you :-) This is my query so far: