Liam Fell
Liam Fell

Reputation: 1320

Joining multiple WordPress MySQL tables

I'm attempting to join four WordPress tables the schema can be seen here, the query returns nothing though.

Can anyone spot any errors here? I've been studying this for a while and can't see any mistakes

I'm passing in some string values here, the problem seems to be with the inner joins though, or rather the joins on 'term_taxonomy' and 'terms'. If I comment these out the query works. I'm not actually doing anything with the additional tables I'm joining yet. I will be at a later date though.

$sql = 'SELECT DISTINCT id, a.* FROM ' . $wpdb->posts . ' a '
            . ' INNER JOIN ' . $wpdb->term_relationships . ' b ON a.ID = b.object_id '
            . ' INNER JOIN ' . $wpdb->term_taxonomy . 'c ON b.term_taxonomy_id = c.term_taxonomy_id '
            . ' INNRER JOIN ' . $wpdb->terms . ' d ON c.term_id = d.term_id '
            . ' WHERE a.post_type = "product" '
            . ' AND b.term_taxonomy_id = ' . $grouped_id . ' '
            . ' AND id NOT IN ( '
            . ' SELECT object_id FROM ' . $wpdb->term_relationships . ' '
            . ' WHERE term_taxonomy_id IN (' . $sql_filter . ') '
            . ') '
            . $sql_like;

Upvotes: 0

Views: 441

Answers (1)

Tdelang
Tdelang

Reputation: 1308

In the terms join you have

. ' INNRER JOIN ' . $wpdb->terms . ' d ON c.term_id = d.term_id '

INNRER should be INNER

Upvotes: 2

Related Questions