使用自定义帖子类型时,类别未按预期工作

时间:2011-05-30 作者:zac

我有一个自定义的帖子类型设置,如下所示:

    add_action(\'init\', \'portfolio_register\');

function portfolio_register() {
 $labels = array(
    \'name\' => _x(\'Photos\', \'post type general name\'),
    \'singular_name\' => _x(\'Portfolio Item\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'portfolio item\'),
    \'add_new_item\' => __(\'Add New Portfolio Item\'),
    \'edit_item\' => __(\'Edit Portfolio Item\'),
    \'new_item\' => __(\'New Portfolio Item\'),
    \'view_item\' => __(\'View Portfolio Item\'),
    \'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() . \'/article16.png\',
            \'rewrite\' => true,
            \'capability_type\' => \'post\',
            \'hierarchical\' => false,
            \'menu_position\' => 4,
            \'taxonomies\' => array(\'post_tag\',\'category\'),
            \'supports\' => array(\'title\',\'editor\',\'comments\',\'trackbacks\',\'revisions\',\'custom-fields\',\'page-attributes\',\'thumbnail\', \'excerpt\', \'tags\')
          ); 
它把所有的元框都拉了进来,单页的一切都很好。

在主页上,我从特色类别中查询如下:

根据斯巴达克斯的建议进行编辑

<?php 
    $args = array(\'category_name\' => \'featured\',
    \'post_type\' => array (\'post\',\'Photos\'),
    \'posts_per_page\' => 20);

    $the_query = new WP_Query($args);
    while ($the_query->have_posts()) : $the_query->the_post();?>
        <?php //getImage(1); ?>
        <div class="featuredSlide">
            <a href="<?php the_permalink(); ?>">
            <img src="<?php bloginfo(\'template_url\'); ?>/scripts/timthumb.php?src=<?php echo get_first_attachment() ?>&w=500&h=500&a=b&zc=1&q=80" alt="<?php the_title(); ?>" /></a>
        <?php the_title(); ?>
        </div>
    <?php endwhile; ?>
这对我写的普通帖子很好,但自定义帖子类型类别中的帖子都不会被拉入这个特色类别查询。有人能看到哪里出了问题,或者对我应该寻找什么有什么建议吗?

1 个回复
最合适的回答,由SO网友:anu 整理而成

您需要将自定义帖子类型添加到WP\\U查询调用中:

$args = array(\'category_name\' => \'featured\',
              \'post_type\' => array (\'post\',\'Photos\'),
               posts_per_page\' => 20);
$the_query = new WP_Query($args);
//continue with your loop

结束

相关推荐

是否从wp_list_categories中筛选“非活动”类别?

我想在类别编辑器屏幕中添加一个复选框,以允许“停用”类别(可能是在网站所有者处理类别内容和帖子时)。完成此操作后,我可以选择哪些选项来排除设置为“非活动”的类别?我认为可以这样做的一种方法是,只需在wp\\u list\\u类别上运行一个过滤器,然后在exlude=list中插入一个实用程序函数,该函数将返回选中inactive为true的所有cat\\u id。还有其他方法吗?