我在使用wp_insert_posts
插入自定义帖子时遇到了一个特殊问题。
情形:
order
到目前为止我尝试了什么
检查帖子类型注册码是否包含任何不兼容的设置,尝试了所有组合 - >值得注意。这是我最接近问题的地方:wp_insert_post entries not showing in admin content list
通过WPML论坛浏览所有与类似问题相关的帖子,尝试了其中提供的步骤(尽管大多数人都在谈论添加翻译)
发布插入代码:
$post_id = wp_insert_post([
"post_type" => "order",
"post_content" => "",
"post_title" => $order->Name() . '<' . $order->Email() . '>',
"post_status" => "publish",
"post_author" => 1
]);
update_post_meta($post_id, 'order_details', '{"some":"json here"}');
帖子会被插入到表格中,管理员中的列表页面会显示总计数,但帖子不会显示在列表中。
帖子类型注册码
if ( ! function_exists('ls_so_order') ) {
// Register Custom Post Type
function ls_so_order() {
$labels = array(
'name' => _x( 'Orders', 'Post Type General Name', 'ls-simple-order' ),
'singular_name' => _x( 'Order', 'Post Type Singular Name', 'ls-simple-order' ),
'menu_name' => __( 'Orders', 'ls-simple-order' ),
'name_admin_bar' => __( 'ProductOrder', 'ls-simple-order' ),
'archives' => __( 'Order Archives', 'ls-simple-order' ),
'attributes' => __( 'Order Attributes', 'ls-simple-order' ),
'parent_item_colon' => __( 'Parent Order:', 'ls-simple-order' ),
'all_items' => __( 'All Orders', 'ls-simple-order' ),
'add_new_item' => __( 'Add New Order', 'ls-simple-order' ),
'add_new' => __( 'Add New', 'ls-simple-order' ),
'new_item' => __( 'New Order', 'ls-simple-order' ),
'edit_item' => __( 'Edit Order', 'ls-simple-order' ),
'update_item' => __( 'Update Order', 'ls-simple-order' ),
'view_item' => __( 'View Order', 'ls-simple-order' ),
'view_items' => __( 'View Orders', 'ls-simple-order' ),
'search_items' => __( 'Search Order', 'ls-simple-order' ),
'not_found' => __( 'Not found', 'ls-simple-order' ),
'not_found_in_trash' => __( 'Not found in Trash', 'ls-simple-order' ),
'featured_image' => __( 'Featured Image', 'ls-simple-order' ),
'set_featured_image' => __( 'Set featured image', 'ls-simple-order' ),
'remove_featured_image' => __( 'Remove featured image', 'ls-simple-order' ),
'use_featured_image' => __( 'Use as featured image', 'ls-simple-order' ),
'insert_into_item' => __( 'Insert into order', 'ls-simple-order' ),
'uploaded_to_this_item' => __( 'Uploaded to this order', 'ls-simple-order' ),
'items_list' => __( 'Orders list', 'ls-simple-order' ),
'items_list_navigation' => __( 'Orders list navigation', 'ls-simple-order' ),
'filter_items_list' => __( 'Filter orders list', 'ls-simple-order' ),
);
$args = array(
'label' => __( 'Order', 'ls-simple-order' ),
'description' => __( 'Simple Order Orders', 'ls-simple-order' ),
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'custom-fields' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-cart',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'capability_type' => 'page',
);
register_post_type( 'order', $args );
}
add_action( 'init', 'ls_so_order', 0 );
}
答案 0 :(得分:0)
你能尝试这样做吗?
// example.js
var foods = ['', ''];
var drinks = ['', ''];
答案 1 :(得分:0)
在我能找到的每个论坛中来回走动,并且修补@miguelcalderons答案后,我找到了罪魁祸首,这是一个非常简单,虽然安静隐藏的东西。
<强> WordPress Reserved Terms 强>
WordPress有一长串保留条款,order
就是其中之一。
在用不同的字符串替换自定义帖子类型slug后,它立即开始工作。