I have a custom post type with a custom backend page.
I'm creating posts of that type using this code:
$postarr = array(
"post_type" => "product_settings",
"post_status" => "published",
"post_title" => "$ean $name",
"post_content" => "$ean $name", // to satisfy WP requirement
"meta_input" => array("ean" => $ean)
);
$id = wp_insert_post($postarr);
if (!$id)
echo "ERR: unable to create post for product $name";
else
update_field("ean", $ean, $id); // THis is an ACF custom field
However, on the backend page, the posts I auto-generate are being counted, but there's no way to make them show up in the list! The only one that's showing is one I created manually in the backend.
I tried all the display options, searching for a string I know is in those auto-generated posts... nothing.
What am I overlooking while generating those posts?
This is the code for the custom post type, should be fairly straightforward:
register_post_type( 'product_settings',
array(
'labels' => array(
'name' => __( 'Produkte' ),
'singular_name' => __( 'Produkt' ),
'add_new_item' => __('Neues Produkt')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'product_settings'),
'taxonomies' => array( 'product_settings' ),
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
)
);
I have a custom post type with a custom backend page.
I'm creating posts of that type using this code:
$postarr = array(
"post_type" => "product_settings",
"post_status" => "published",
"post_title" => "$ean $name",
"post_content" => "$ean $name", // to satisfy WP requirement
"meta_input" => array("ean" => $ean)
);
$id = wp_insert_post($postarr);
if (!$id)
echo "ERR: unable to create post for product $name";
else
update_field("ean", $ean, $id); // THis is an ACF custom field
However, on the backend page, the posts I auto-generate are being counted, but there's no way to make them show up in the list! The only one that's showing is one I created manually in the backend.
I tried all the display options, searching for a string I know is in those auto-generated posts... nothing.
What am I overlooking while generating those posts?
This is the code for the custom post type, should be fairly straightforward:
register_post_type( 'product_settings',
array(
'labels' => array(
'name' => __( 'Produkte' ),
'singular_name' => __( 'Produkt' ),
'add_new_item' => __('Neues Produkt')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'product_settings'),
'taxonomies' => array( 'product_settings' ),
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
)
);
Share
Improve this question
edited Oct 11, 2017 at 20:49
Pekka
asked Oct 11, 2017 at 20:36
PekkaPekka
5422 gold badges9 silver badges33 bronze badges
3
- That's incredibly strange. Are you sure there is nothing hooked to filters that would interfere while auto-generating the posts? – Johansson Commented Oct 12, 2017 at 0:21
- @JackJohansson pretty sure! It's a vanilla WP install with a custom post type and a custom taxonomy, nothing more. – Pekka Commented Oct 12, 2017 at 8:04
- @JackJohansson argh, I looked into the database and it turns out it was a simple typo! See below. – Pekka Commented Oct 12, 2017 at 8:27
2 Answers
Reset to default 2Ugggggggh.
"post_status" => "published",
is incorrect. It should be
"post_status" => "publish",
This apparently puts posts into a state of limbo in which they're not visible in the list (but still counted for some reason).
According to the docs post_title
& post_content
are required, Wordpress will not generate an empty published post.
https://developer.wordpress/reference/functions/wp_insert_post/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745150223a4613834.html
评论列表(0条)