自定义帖子类型表中未显示已保存的自定义帖子类型条目

时间:2012-10-17 作者:ifdion

我已经使用自定义插件注册了几个自定义帖子类型。它们似乎都很好用。所有都列在Post菜单下。

保存自定义帖子条目时出现问题。自定义的post类型保存在数据库中,permalink从前端就可以正常工作。但奇怪的是,自定义post类型表是空的。post状态过滤器显示“所有(1)|已发布(1)”。Screenshot

经过调查,我发现这种情况发生在第二次register_post_type() 在我的自定义插件中调用。

如何解决此问题?

非常感谢。

Added

这里是register\\u post\\u类型代码的2。它们中的每一个都是从不同的文件调用的,使用include_once (\'product/product.php\');include_once (\'order/order.php\');

add_action(\'init\', \'product_post_type\', 0 );

function product_post_type() {

$product_labels = array(
    \'name\' => _x(\'Product\', \'post type general name\'),
    \'singular_name\' => _x(\'Product\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'investment\'),
    \'add_new_item\' => __(\'Add New Product\'),
    \'edit_item\' => __(\'Edit Product\'),
    \'new_item\' => __(\'New Product\'),
    \'view_item\' => __(\'View Product\'),
    \'search_items\' => __(\'Search Product\'),
    \'not_found\' =>  __(\'No product found\'),
    \'not_found_in_trash\' => __(\'No product found in Trash\'), 
    \'parent_item_colon\' => \'\',
    \'menu_name\' => \'Product\'
);
$product_args = array(
    \'labels\' => $product_labels,
    \'public\' => true,
    \'can_export\' => true,
    \'publicly_queryable\' => true,
    \'show_ui\' => true, 
    \'show_in_menu\' => true, 
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'product\' ),
    \'capability_type\' => \'post\',
    \'map_meta_cap\' => true,
    \'has_archive\' => true, 
    \'hierarchical\' => true,
    \'menu_position\' => 6,
    \'show_in_nav_menus\' => false,
    \'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'comments\')
); 

register_post_type(\'product\',$product_args);

}


add_action(\'init\', \'order_post_type\', 0 );

function order_post_type() {

$order_labels = array(
    \'name\' => _x(\'Order\', \'post type general name\'),
    \'singular_name\' => _x(\'Order\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'investment\'),
    \'add_new_item\' => __(\'Add New Order\'),
    \'edit_item\' => __(\'Edit Order\'),
    \'new_item\' => __(\'New Order\'),
    \'view_item\' => __(\'View Order\'),
    \'search_items\' => __(\'Search Order\'),
    \'not_found\' =>  __(\'No order found\'),
    \'not_found_in_trash\' => __(\'No order found in Trash\'), 
    \'parent_item_colon\' => \'\',
    \'menu_name\' => \'Order\'
);
$order_args = array(
    \'labels\' => $order_labels,
    \'public\' => true,
    \'publicly_queryable\' => true,
    \'show_ui\' => true, 
    \'show_in_menu\' => true, 
    \'query_var\' => true,
    \'rewrite\' => true,
    \'capability_type\' => \'post\',
    \'has_archive\' => true, 
    \'hierarchical\' => true,
    \'menu_position\' => 8,
    \'supports\' => array(\'title\')


); 

register_post_type(\'order\',$order_args);

}

1 个回复
最合适的回答,由SO网友:Milo 整理而成

某些用作帖子类型名称的单词会产生不可预测的结果,在您的情况下,单词order 是保留项,导致查询出现问题。将该帖子类型名称更改为唯一的名称,管理员UI将正常工作。

结束

相关推荐