嘿,我目前非常沮丧,无法弄清楚这一点,我已经在整个互联网上查看了。我有一个名为“portfolio”的自定义帖子类型,我有一个名为“categories”的分类,其中包含“photography”和“catalog design”两个类别。我正在使用此代码
query_posts(array(
'post_type' => 'portfolio',
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'catalog-design',
'terms' => 'catalog-design'
)
));
出于某种原因,它没有听分类法,只是显示投资组合中的所有内容。这个我也试过了还是不行
query_posts(array(
'post_type' => 'portfolio',
'category' => 'catalog-design'
));
如果有人知道如何解决这个问题,那就太棒了,这里也是创建一切的代码
add_action('init', 'portfolio');
功能投资组合(){
$labels = array(
'name' => _x('Portfolio', 'edit and add portfolio items'),
'singular_name' => _x('Portfolio Item', 'post type singular name'),
'add_new' => _x('Add Portfolio Item', 'Portfolio Item'),
'add_new_item' => __('Add New Portfolio Item'),
'edit_item' => __('Edit Portfolio Item'),
'new_item' => __('New Portfolio Item'),
'view_item' => __('View Portfolio'),
'search_items' => __('Search Portfolio'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/library/images/portfolio.png',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'category', 'editor','thumbnail'),
'taxonomies' => array('category', 'client')
);
register_post_type( 'portfolio' , $args );
}