按自定义帖子类型按类别过滤产品

时间:2015-07-14 09:20:52

标签: wordpress

我已经在我的functions.php。

中编写了这个自定义代码
add_action('init', 'portfolio_register');

function portfolio_register() {

$labels = array(
    'name' => _x('Portfolio', 'post type general name'),
    'singular_name' => _x('Tool', 'post type singular name'),
    'add_new' => _x('Add New Project', 'tool'),
    'add_new_item' => __('Add New Tool'),
    'edit_item' => __('Edit Tool'),
    'new_item' => __('New Tool'),
    'view_item' => __('View Tool'),
    'search_items' => __('Search Toolkit'),
    '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() . '/article16.png',
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','editor','thumbnail')
  ); 

register_post_type( 'portfolio' , $args );
}

register_taxonomy("toolkit", array("portfolio"), array("hierarchical" => true,   "label"     => "Project Categories", "singular_label" => "Tool", "rewrite" => true));

现在我必须按类别过滤项目我试过这个但是没有工作......我尝试了meta_key和meta_value,但仍然没有过滤项目。

`

<ul class="web-list">
<?php
$portfolio = new WP_Query( array( 'post_type' => 'portfolio', 'project-categories'=> 'web' ) );

while ( $portfolio->have_posts() ) : $portfolio->the_post();
$portfolio_img = get_the_ID();
$portfolio_name = get_the_title();

?>
<li><a href="http://www.<?php echo $portfolio_name; ?>" class="entry-thumb">
<div class="web-img-box"><?php echo get_the_post_thumbnail($portfolio_img, 'full') ?></div>
</a><span class="categories-name"><?php echo $portfolio_name; ?></span></li>
<?php endwhile; wp_reset_query(); ?>
</ul>

1 个答案:

答案 0 :(得分:0)

感谢所有人不重播......但我仍然设法使用工具包解决了我的问题。