下面的代码显示了匹配“页面名称”和“类别slug”的帖子..但我试图让它使用自定义分类法。我如何将其纳入下面? 我在我的函数文件中使用它:
function my_get_posts( $category_name )
{
// set the criteria
$args = array(
'numberposts' => -1,
'category_name' => $category_name,
'post_type' => 'custom_type'
);
// return the object array of the posts.
return get_posts( $args );
}
这在我的页面中
<?php
$posts_returned = my_get_posts($post->post_name);
foreach ($posts_returned as $post_returned) {
$postlink = get_post_permalink($post_returned->ID);
?>
HTML HERE
<?php } ?>
答案 0 :(得分:0)
完成了工作
function sherwood_get_posts( $category_name )
{
// set the criteria
$args = array(
'numberposts' => -1,
'post_type' => 'custom_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_cat',
'field' => 'slug',
'terms' => array($category_name))
)
);
// return the object array of the posts.
return get_posts( $args );
}
?>