多くの人がこれに反対票を投じようとしていることは知っていますが、それは正当な質問であり、他の回答が役に立たなかったので、とにかく尋ねます。まずコードを表示してから質問します。
<?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 つの投稿タイプを登録します。1 つはカテゴリで、もう 1 つはその子です。
例えば:
http://www.the-tack-shop.co.uk/our_items/dsfdfd/
作品
http://www.the-tack-shop.co.uk/our_items/dsfdfd/fggfdg/
404 を返します。
投稿タイプを登録するとき、どちらもほとんど同じ引数を持ちます。また、親投稿を正しく設定する親ドロップダウンを複製するメタボックスを追加したことにも気付くかもしれません....
2番目が機能しない理由を知っている人はいますか? (flush_rewite_rule に注意してください。パーマリンク ページに移動しても機能しません)。
誰かが助けてくれることを願って、
よろしく