Skip to main content
need to remove single quotes from join ON statement
Source Link
helgatheviking
  • 14.5k
  • 8
  • 64
  • 115

Sorry guys, I just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ('p p.ID'ID = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don't have to define an alias for $wpdb->terms in FROM clause.

Sorry guys, I just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ('p.ID' = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don't have to define an alias for $wpdb->terms in FROM clause.

Sorry guys, I just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ( p.ID = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don't have to define an alias for $wpdb->terms in FROM clause.

Sorry guys,

  I just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ('p.ID' = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don´tdon't have to define an alias for $wpdb->terms$wpdb->terms in FROMFROM clause.

Sorry guys,

  just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ('p.ID' = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don´t have to define an alias for $wpdb->terms in FROM

Sorry guys, I just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ('p.ID' = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don't have to define an alias for $wpdb->terms in FROM clause.

Source Link

Sorry guys,

just found the solution:

SELECT p.post_name, t.name as clientName 
FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON ('p.ID' = tr.object_id)
INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
WHERE   p.post_status = 'publish' 
    AND p.post_type = 'portfolio'
    AND tt.taxonomy = 'clients' 
ORDER BY p.post_date DESC

I just don´t have to define an alias for $wpdb->terms in FROM