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 に答える