1

I have a declared a custom post type in function.php like this :

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

Then I try to retrive them in a template file like this :

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

It does not work, it retrieve the normal posts. If I use the post_type 'event' it works (it retrieve events from Event manager plugin).

What is wrong ?

bokan
  • 3,601
  • 2
  • 23
  • 38

2 Answers2

0

Try:

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

And also:

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

avexdesigns
  • 499
  • 3
  • 8
  • I tried this also, it doesn't works. The only way is to write query by hand like there http://stackoverflow.com/questions/1155565/query-multiple-custom-taxonomy-terms-in-wordpress-2-8/1161915#1161915 . – bokan Sep 09 '12 at 21:55
  • Did you flush the rewrite rules as well? Displaying custom post types is normally done the way I described above. Perhaps check how you are setting up the post type. – avexdesigns Sep 10 '12 at 00:16
0

I finally manage to get the posts using get_posts()

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

$myposts = get_posts( $args );

foreach( $myposts as $post ) :
    setup_postdata($post);
    ...
endforeach;
bokan
  • 3,601
  • 2
  • 23
  • 38