Ottenere un elenco di post da una tassonomia personalizzata in WordPress
10 ago 2011, 03:19:45
Visualizzazioni: 14.1K
Voti: 1
Posso ottenere l'ID o lo slug della categoria per la mia tassonomia personalizzata senza problemi, ma poi ho bisogno di recuperare tutti i post come array per quella voce di tassonomia. Il mio codice è il seguente:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
endwhile;
Quando aggiungo 'category_name'=>'my_taxonomy_name' all'array $args, provoca semplicemente che $the_query sia vuoto anche se so che ci sono post presenti. Ho anche provato a cambiarlo con 'cat'=>22, ma presenta lo stesso problema.
Qualcuno può aiutarmi?
Grazie John

user505988
125
Tutte le risposte alla domanda
1
0
Consulta i Parametri della Tassonomia.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'taxonomy_name',
'field' => 'id',
'terms' => '22'
)
)
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
//contenuto
endwhile;
?>

Evan Yeung
3.52K
10 ago 2011 03:26:44
Domande correlate
2
risposte