Wordpress自定义帖子类型 - 404

时间:2012-08-20 07:52:35

标签: wordpress http-status-code-404 custom-post-type

我知道有很多人会对此投票,但不管怎样我会问,这是一个合法的问题,没有其他答案有帮助。我将首先显示代码,然后询问。

<?php

    add_action('init', 'items_register');
    add_action("admin_init", "admin_init");
    add_action('save_post', 'save_details');

    function save_details(){
        global $post;
        update_post_meta($post->ID, "shelf_image", $_POST["shelf_image"]);
    }

    function items_register() {

        $__Test_items_labels = array(
            'name' => _x('Test items', 'post type general name'),
            'sinTestlar_name' => _x('item Item', 'post type sinTestlar name'),
            'add_new' => _x('Add New item', 'item item'),
            'add_new_item' => __('Add New item Item'),
            'edit_item' => __('Edit item Item'),
            'new_item' => __('New item Item'),
            'view_item' => __('View item Item'),
            'search_items' => __('Search items'),
            'not_found' =>  __('Nothing found'),
            'not_found_in_trash' => __('Nothing found in Trash'),
            'parent_item_colon' => ''
        );

        $__Test_items_args = array(
            'labels' => $__Test_items_labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'our_items', 'with_front' => false ),
            'show_in_menu' => 'edit.php?post_type=page',
            'capability_type' => array('page','post'),
            'hierarchical' => true,
            'supports' => array('title','editor','thumbnail','post_attributes')
          ); 

          $__Test_items_cat_labels = array(
            'name' => _x('Test items Categories', 'post type general name'),
            'sinTestlar_name' => _x('items Category Item', 'post type sinTestlar name'),
            'add_new' => _x('Add New item Category', 'category item'),
            'add_new_item' => __('Add New item Category'),
            'edit_item' => __('Edit item Category'),
            'new_item' => __('New item Category'),
            'view_item' => __('View item Category'),
            'search_items' => __('Search item Categories'),
            'not_found' =>  __('Nothing found'),
            'not_found_in_trash' => __('Nothing found in Trash'),
            'parent_item_colon' => ''
        );

        $__Test_items_cat_args = array(
            'labels' => $__Test_items_cat_labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'menu_icon' => 'http://cdn1.iconfinder.com/data/icons/ledicons/cake.png',
            'rewrite' => array( 'slug' => 'our_items', 'with_front' => false ),
            'show_in_menu' => 'edit.php?post_type=page',
            'capability_type' => 'page',
            'hierarchical' => true,
            'supports' => array('title','editor','thumbnail','post_attributes')
        );  

        register_post_type( 'item' , $__Test_items_args );
        register_post_type( 'item_category' , $__Test_items_cat_args );
        flush_rewrite_rules( false );

    }

    function admin_init(){
        add_meta_box("item_parent_meta", "Test item Category", "item_catagory_parent", "item", "side", "low");
    }

    function item_catagory_parent(){
        global $post;
        $args = array( 'post_type' => 'item_category', 'posts_per_page' => 10 );
        $loop = new WP_Query( $args );
        echo '<select name="parent_id" id="parent_id" style="width:100%;">';
        echo '  <option value="">(no parent)</option>';
        foreach( $loop->posts as $key => $obj ) {
            if( $obj->post_status === 'publish' )
                echo '<option ' . ( (int)$post->post_parent === (int)$obj->ID ? 'selected="selected"' : '' ) . ' class="level-0" value="' . $obj->ID . '">' . $obj->post_title . '</option>';
        }
        echo '</select>';
    }


?>

我不完全理解并且需要问这个问题的原因是因为它在一个实例中起作用,而不是在另一个实例中起作用。

上述寄存器有两种类型,一种是类别,一种是它的孩子。

例如:

http://www.the-tack-shop.co.uk/our_items/dsfdfd/

作品

http://www.the-tack-shop.co.uk/our_items/dsfdfd/fggfdg/

返回404。

在注册帖子类型时,他们几乎都有相同的参数。你可能还注意到我已经添加了一个元框,它复制了父下拉列表,它正确地设置了父文章....

有谁知道为什么第二个不起作用? (请注意flush_rewite_rule,对固定链接页面进行操作不起作用)。

希望有人能提供帮助,

此致

1 个答案:

答案 0 :(得分:2)

您可以尝试进入永久链接部分并再次保存!它对我有用