我已经创建了定制的帖子,即解决方案。我使用register_taxonomy创建了分类法,即solution_category。我创建了两个类别
如何通过函电获得?
发布于 2015-07-07 11:27:00
尝试如下:
$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;发布于 2015-07-07 11:47:16
代码:
$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>";
}输出:

https://stackoverflow.com/questions/31267169
复制相似问题