wp查询无法使用自定义帖子类型>类别

时间:2014-07-01 07:33:34

标签: html5 wordpress custom-post-type wp-query

我正在使用html5-blank作为我的主题。

当从标准wordpress帖子类型中提取时,所有查询都能正常工作...当尝试从'html5-blank'帖子类型中提取时,它会中断。

以下是查询:

<?php $my_query = new WP_Query('category_name=spotlight&showposts=2');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
    <!-- pull thumbnail image -->
    <article class="article_wrap">
        <div class="widget_thumb">
            <a href="<?php echo get_permalink(); ?>">
                <?php echo get_the_post_thumbnail(); ?>
        </div>
        <h1 class="widget_title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
        <p class="widget_spot_description"><?php the_excerpt(); ?></p>
    </article>
        <?php endwhile; ?>

这是functions.php:

function create_post_type_html5()
{
register_taxonomy_for_object_type('category', 'html5-blank'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'html5-blank');
register_post_type('html5-blank', // Register Custom Post Type
    array(
    'labels' => array(
        'name' => __('HTML5 Blank Custom Post', 'html5blank'), // Rename these to suit
        'singular_name' => __('HTML5 Blank Custom Post', 'html5blank'),
        'add_new' => __('Add New', 'html5blank'),
        'add_new_item' => __('Add New HTML5 Blank Custom Post', 'html5blank'),
        'edit' => __('Edit', 'html5blank'),
        'edit_item' => __('Edit HTML5 Blank Custom Post', 'html5blank'),
        'new_item' => __('New HTML5 Blank Custom Post', 'html5blank'),
        'view' => __('View HTML5 Blank Custom Post', 'html5blank'),
        'view_item' => __('View HTML5 Blank Custom Post', 'html5blank'),
        'search_items' => __('Search HTML5 Blank Custom Post', 'html5blank'),
        'not_found' => __('No HTML5 Blank Custom Posts found', 'html5blank'),
        'not_found_in_trash' => __('No HTML5 Blank Custom Posts found in Trash', 'html5blank')
    ),
    'public' => true,
    'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
    'has_archive' => true,
    'supports' => array(
        'title',
        'editor',
        'excerpt',
        'thumbnail'
    ), 

    'can_export' => true, // Allows export in Tools > Export
    'taxonomies' => array(
        'post_tag',
        'category'
    ) // Add Category and Post Tags support
));


}

我正在检查自定义帖子类型中的类别框,但查询不会填充帖子。它仅显示标准帖子类型的帖子。

Noooooooo!

1 个答案:

答案 0 :(得分:0)

您应该在wp查询中指定帖子类型:

$my_query = new WP_Query('category_name=spotlight&posts_per_page=2&post_type=html5-blank');

修改:使用posts_per_page替换已弃用的showposts