Why a custom post_type could not be retrieved with query_posts?

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 ?

Answers


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


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;

Need Your Help

Why does matplotlib fill_between draw edgelines only on a PDF?

python pdf matplotlib png

In python's matplotlib.fill_between the following minimal working example below draws correctly to the screen, and to the .png. In the resulting .pdf however, the edge lines are still drawn. How ca...

Height of 2-3-4 tree

java tree height

I have a working snippet to use for a regular tree comprising nodes. Now I just need to fiddle with it to work for 2-3-4 trees, which should be easier, since each path is the same distance, since i...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.