wordpress - Display posts based on custom taxonomy terms -


hi trying display posts of custom taxonomy based on terms.the below code returns 1 after other need 1 particular term. example have 2 cities under custom taxonomy city-guide-cities lets paris , newyork.i need display posts under paris. tried in wpq array pass paris term arg display paris posts loop works. means paris posts display under first paris under newyork.i not want newyork display in there or not want loop run once paris or newyork loaded.

<?php $terms = get_terms('city-guide-cities');  foreach ($terms $term) { $wpq = array ('taxonomy'=>'city-guide-cities','term'=>$term->slug); $myquery = new wp_query ($wpq); $article_count = $myquery->post_count; echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">"; echo $term->name; echo "</h3>"; if ($article_count) { echo "<ul>"; while ($myquery->have_posts()) : $myquery->the_post();   echo "<li><a href=\"".get_permalink()."\">".$post->post_title."</a></li>"; endwhile; echo "</ul>"; } } ?> 

see https://codex.wordpress.org/class_reference/wp_query#taxonomy_parameters. should work you.

$query = new wp_query(  array(      'post_type' => 'city-guide',     'tax_query' => array(         array(             'taxonomy' => 'city-guide-cities',             'field'    => 'slug',             'terms'    => 'paris',         ),     )  )  ); 

you can chain these, , or or, multiple term queries need.


Comments

Post a Comment

Popular posts from this blog

filehandler - java open files not cleaned, even when the process is killed -

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -