-1

我知道很多人会对此投反对票,但无论如何我都会问,因为这是一个合法的问题,没有其他答案有帮助。我将首先显示代码然后询问。

<?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>';
    }


?>

我不完全理解并且需要问这个问题的原因是因为它在一种情况下有效,但在另一种情况下无效。

以上注册了 2 种帖子类型,一种是类别,一种是子类别。

例如:

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,转到永久链接页面不起作用)。

希望有人能帮忙,

问候

4

1 回答 1

2

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

于 2012-09-16T00:44:54.383 回答