1

我在 function.php 中声明了一个自定义帖子类型,如下所示:

register_post_type('movies', array(
    'label' => __("Movies", TEMPLATENAME),
    'singular_label' => __("Movie", TEMPLATENAME),
    'public' => true,
    'show_ui' => true,
    'exclude_from_search' => true,
    'publicly_queryable' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'permalink_epmask' => EP_PERMALINK,
    'rewrite' => array('slug' => 'cine', 'with_front'=> false),
    'query_var' => 'movies',
    'show_in_nav_menus' => true,
    'menu_position' => 20,
    'description' => __("These Movies will be automatically displayed on the « Movies » page.", TEMPLATENAME),
    'labels' => array('add_new_item' => __( "Ajouter une movie", TEMPLATENAME), 'add_new' => __( "Ajouter une movie", TEMPLATENAME), 'edit_item' => __( "Modifier la movie", TEMPLATENAME), 'new_item' => __( "Nouvelle movie", TEMPLATENAME), 'view_item' => __( "Voir la movie", TEMPLATENAME), 'search_items' => __( "Chercher dans toutes les movies", TEMPLATENAME), 'not_found' => __( "Not Found", TEMPLATENAME), 'not_found_in_trash' => __( "No movie found in trash", TEMPLATENAME)),
    'supports' => array('title', 'editor', 'thumbnail',  'excerpt','custom-fields')
    //, 'register_meta_box_cb' => 'movies_box_fields'
));

然后我尝试在这样的模板文件中检索它们:

<?php query_posts(array ( 'post_type' => 'movies' )); ?>

它不起作用,它检索正常的帖子。如果我使用 post_type 'event' 它可以工作(它从事件管理器插件中检索事件)。

怎么了 ?

4

2 回答 2

0

尝试:

<?php $loop = new WP_Query( array( 'post_type' => 'movies', 'posts_per_page' => 10 ) ); ?>

并且:

http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

于 2012-09-09T20:42:20.190 回答
0

我终于设法使用 get_posts() 获取帖子

$args=array(
    'post_type'=> 'movies',
    'numberposts'=> -1
    );

$myposts = get_posts( $args );

foreach( $myposts as $post ) :
    setup_postdata($post);
    ...
endforeach;
于 2012-09-10T14:00:11.347 回答