最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Auto-generated posts not showing in backend (but being counted!)

programmeradmin0浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 2

Ugggggggh.

"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/

发布评论

评论列表(0)

  1. 暂无评论