2012-05-07 197 views
0

嘿,大家我目前非常沮丧,无法弄清楚这一点已经看遍了整个互联网。我有一个称为“投资组合”的自定义帖子类型,我有一个名为“类别”的分类法,其中包含两个类别“摄影”和“目录设计”。我使用这个代码WordPress的自定义帖子类型和分类仍然显示帖子类型的所有帖子

  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); 

}

回答

0

'类别' 查找的ID。尝试:

query_posts(array(
     'post_type' => 'portfolio', 
     'category_name' => 'catalog-design' 
)); 

或者:

$cat = get_cat_ID('catalog-design'); 
query_posts(array(
     'post_type' => 'portfolio', 
     'category' => $cat 
)); 
+0

这就是我最终找到并得到它的工作。 –

相关问题