Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/07/2012, 08:18
albertcito
 
Fecha de Ingreso: diciembre-2007
Mensajes: 169
Antigüedad: 17 años, 1 mes
Puntos: 6
Pregunta Duda consulta Anidada con

Es Wordpress, en breve:
  • Tengo 2 taxonomy: instituciones y area_tematica
  • Tengo el ID de una institución (id_term) y obtengo todas los ID de los post asociados a ese term (select anidado)
  • Ahora tengo un conjunto de ID de post, quiero obtener todas los id_term de el taxonomy area_tematica

Mi llamada a la BD:
Si la hago así mi consulta me retorna solo 1 resultado.
Código MySQL:
Ver original
  1.                     t.term_id,
  2.                     t.name
  3.                 FROM
  4.                     $wpdb->term_relationships tr,
  5.                     $wpdb->term_taxonomy tt,
  6.                     $wpdb->terms t
  7.                 WHERE
  8.                     tr.object_id IN (SELECT
  9.                                        group_concat(p.ID)
  10.                                     FROM
  11.                                         $wpdb->term_relationships tr,
  12.                                         $wpdb->term_taxonomy tt,
  13.                                         $wpdb->terms t,  
  14.                                         $wpdb->posts p
  15.                                     WHERE
  16.                                         tr.object_id = p.ID AND
  17.                                         tr.term_taxonomy_id = tt.term_taxonomy_id AND
  18.                                         tt.term_id = t.term_id AND
  19.                                         t.term_id = '$institucion' AND
  20.                                         p.post_status = 'publish'
  21.                                     )
  22.                     AND
  23.                     tr.term_taxonomy_id = tt.term_taxonomy_id AND
  24.                     tt.term_id += t.term_id AND
  25.                     tt.taxonomy = '$taxonomy'

Eso se transforma es esto:

De está manera me retorna bien los resultados
Código MySQL:
Ver original
  1.                     t.term_id,
  2.                     t.name
  3.                 FROM
  4.                     wp_term_relationships tr,
  5.                     wp_term_taxonomy tt,
  6.                     wp_terms t
  7.                 WHERE
  8.                     tr.object_id IN (20,32,,54,76,88,99,61,22)
  9.                     AND
  10.                     tt.taxonomy = 'area_tematica' AND
  11.                     tr.term_taxonomy_id = tt.term_taxonomy_id AND
  12.                     tt.term_id = t.term_id


Y el resultado de eso solo me devuelve una sola fila, o sea [t.term_id, t.name] y debería devolver más ya que tengo más terms asociados.

Aquí la BD de Wordpress, si alguien me puede ayudar por favor.
__________________
Inspiracion

Última edición por albertcito; 09/07/2012 a las 08:33