Ottieni Post per Custom Post Type, Tassonomia e Termine
Ok, ho un Custom Post Type chiamato "Services". Questo custom post type ha una tassonomia chiamata "Areas" e ci sono 5 termini in quella tassonomia.
Mettiamo che ho 10 post in "Services" e ci sono 5 post nel termine "Painting" e altri 5 nel termine "Photography".
Ho bisogno di poter interrogare i post da "Services" ma invece di mostrare tutti e 10 i post, mostrare solo i 5 associati a "Painting".
Al momento sono in grado di interrogare per tassonomia e termini, ma questo mostrerà tutti i post da "services" senza filtro per termine.
In pratica, devo interrogare i post per post_type dal termine che scelgo.
Qualsiasi aiuto sarebbe fantastico. Grazie.
<ul id="service-list">
<?php
$args = array('tax_query' => array( array('taxonomy' => 'areas', 'field' => 'slug','terms' => 'painting')));
$the_query = new WP_Query( $args );
if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<li class="service">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</li><!-- /.service -->
<?php endwhile; else: ?>
<p>Nessun contenuto qui.</p>
<?php endif; wp_reset_postdata(); ?>
</ul><!-- #service-list -->
Quindi se potessi solo specificare negli $args da quale post type ottenere i post, questo sarebbe risolto.
Questa è la risposta alla domanda :)
<?php
$args = array(
'post_type'=> 'services',
'areas' => 'painting',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
if($the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
$the_query->the_post();
// il contenuto va qui
endwhile;
wp_reset_postdata();
else:
endif;
?>
