我创建了自定义帖子即解决方案。我使用register_taxonomy
即solution_category创建了分类法。我创建了两个类别
如何通过功能发布?
答案 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>";
}
<强>输出:强>