如何从分类学中获取帖子名称

时间:2015-07-07 11:20:37

标签: php wordpress

我创建了自定义帖子即解决方案。我使用register_taxonomy即solution_category创建了分类法。我创建了两个类别

  1. 按功能
  2. 按行业划分
  3. 如何通过功能发布?

2 个答案:

答案 0 :(得分:1)

试试这个:

$cargs = array(
    'post_type' => 'my_post_type',
    'posts_per_page'=>-1,
    'tax_query' => array(
            'taxonomy' => 'my_taxonomy',
            'field' => 'slug',
            'terms' => 'webdesign'
        )       
);
$cwp_query = new WP_Query($cargs);
while ($cwp_query->have_posts()) : $cwp_query->the_post(); 
print_r($post);
endwhile;

答案 1 :(得分:0)

<强> CODE:

$terms = get_terms('solution_category');
// Initially get all categories

foreach ($terms as $term) 
{
   $wpq = array ('taxonomy'=>'solution_category','term'=>$term->slug);
   $query = new WP_Query ($wpq);
   $article_count = $query->post_count;

   echo "<h3 Style='border-bottom: 1px solid #ccc;' class=\"term-heading\" id=\"".$term->slug."\">";
   echo $term->name;
   echo "</h3>";

   if ($article_count) {
      echo "<ul>";
      $posts = $query->posts;
      foreach ($posts as $post) {
      echo "<li><a href=\"".get_permalink()."\">".$post->post_title."     </a></li>";
   }
   echo "</ul>";
}

<强>输出:

enter image description here