Home › Forum › Problemi Vari con WP › Creare una query usando più Tag Parameters
-
AutorePost
-
-
21 Ottobre 2010 alle 9:00 #15353microtagPartecipante
Mi piaceebbe sapere (anche se dubito fortemente) se esiste la possbilità di creare una lista di post con che contengono dei precisi TAGS
So che usando il parametro ‘tag__and’ => array(1,2) il risultato è una lista di post che hanno sia il tag ID 1 ed il tag ID 2.
La domanda è: posso usare più parametri assieme?
Esempio:
‘tag__and’ => array(1,2),
‘tag__and’ => array(3,5) ,
‘tag__in’ => array(10,15,20)
L’esmpio non funziona, ma esiste la possibilità di creare una query in cui ci sono post che devono avere sia il tagID 1 e 2, ma che possono avere anche il TAG ID 3 e 5 oppure il tag ID 10, 15, 20?
Grazie
-
21 Ottobre 2010 alle 9:27 #77847SteveAglAmministratore del forum
No non con quei tag… poi dipende che devi fare esattamente…
-
21 Ottobre 2010 alle 9:40 #77848microtagPartecipante
Prova a farti un esempio di quello che vorrei fare…
Mettiamo il caso di avere un blog con mille post, ed ogni post possiede 3/5 tags.
Prendiamo in esame una decina di tag fra i 500 inseriti: frutta|banana|mela|pera|pesca|fruttivendolo|pesce|carne|torta|cucina
Mi piacerebbe generare degli elenchi di post bene precisi:
Esempio:
lista 01: tutti i post che contengono i tags frutta+banana (e fino qui tutto ok, nessun problema)
lista 02: tutti i post che contengono i tags frutta+banana ma che possono contenere anche frutta+mela (e qui non riesco proprio)
-
21 Ottobre 2010 alle 10:42 #77849SteveAglAmministratore del forum
e perchè non fare per il secondo i tag__in di frutta mela e banana? Mi sa che però usi i tag in maniera “sbagliata” o al struttura che vuoi dare sarebbe meglio se fatta con delle tassonomie apposite…
-
21 Ottobre 2010 alle 12:21 #77852microtagPartecipante
Perchè usando il tag__in il risultato è di avere post che hanno come TAG o frutta o mela, mentre il risultato he voglio ottenere è ben diverso.
-
21 Ottobre 2010 alle 12:27 #77853SteveAglAmministratore del forum
Bhe l’and è univoco.. altrimenti occorre farsi una query ad hoc in SQL
-
21 Ottobre 2010 alle 12:57 #77856microtagPartecipante
Immaginavo.
Grazie comunque… )
-
21 Ottobre 2010 alle 13:30 #77858SteveAglAmministratore del forum
Una cosa tipo:
SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->term_taxonomy.term_id = 3
AND ($wpdb->term_taxonomy.term_id = 6 OR $wpdb->term_taxonomy.term_id =
AND $wpdb->term_taxonomy.taxonomy = ‘tag’
AND $wpdb->posts.post_status = ‘publish’
dove la categoria ID 3 è frutta e la 6 e 8 sono pere e mele… questa query passata a query_post o altro ti darà un loop con i dati che ti servono… da provare perchè fatta cosଠsenza alcun test
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.