自定义发布类型全部视图中未显示自定义发布状态

时间:2017-02-11 作者:Colin Richardson

我为我们的WP网站创建了一个简单的插件,允许我们输入我们发送的产品。

为此,我创建了一个名为“order\\u packing”的新帖子类型,并在这2个新帖子状态中添加了“In packing”、“Sent”。

我的问题是,清单正确地显示了所有(2)个总数中的装箱单,但没有列出装箱单。如果单击“已发送”状态,则列表中会同时显示这两个状态。所以我的问题是数据在那里,但它们没有显示在“全部”选项卡下。

下面是创建Post类型的代码,这一切都很完美

enter code here    register_post_type( \'order_packing\',
    array(
        \'labels\'              => array(
        \'name\'                  => __( \'Order Packing\', \'tgplugin\' ),
        \'singular_name\'         => _x( \'Order Packing\', \'order_packing post type singular name\', \'tgplugin\' ),
        \'add_new\'               => __( \'Add Packing List\', \'tgplugin\' ),
        \'add_new_item\'          => __( \'Add Packing List\', \'tgplugin\' ),
        \'edit\'                  => __( \'Edit\', \'tgplugin\' ),
        \'edit_item\'             => __( \'Edit Packing List\', \'tgplugin\' ),
        \'new_item\'              => __( \'New Packing List\', \'tgplugin\' ),
        \'view\'                  => __( \'View Packing List\', \'tgplugin\' ),
        \'view_item\'             => __( \'View Packing List\', \'tgplugin\' ),
        \'search_items\'          => __( \'Search Packing Lists\', \'tgplugin\' ),
        \'not_found\'             => __( \'No Packing Lists found\', \'tgplugin\' ),
        \'not_found_in_trash\'    => __( \'No Packing Lists found in trash\', \'tgplugin\' ),
        \'parent\'                => __( \'Parent Packing List\', \'tgplugin\' ),
        \'menu_name\'             => _x( \'Stock Packing List\', \'Admin menu name\', \'tgplugin\' ),
        \'filter_items_list\'     => __( \'Filter Packing Lists\', \'tgplugin\' ),
        \'items_list_navigation\' => __( \'Packing List navigation\', \'tgplugin\' ),
        \'items_list\'            => __( \'Packing Lists\', \'tgplugin\' ),
    ),
        \'description\'         => __( \'This is where Packing Lists are stored.\', \'tgplugin\' ),
        \'public\'              => false,
        \'show_ui\'             => true,
        \'capability_type\'     => \'packing_list\',
        \'map_meta_cap\'        => true,
        \'publicly_queryable\'  => false,
        \'exclude_from_search\' => true,
        \'show_in_menu\'        => true,
        \'hierarchical\'        => false,
        \'show_in_nav_menus\'   => false,
        \'menu_position\'       => 100,
        \'rewrite\'             => false,
        \'query_var\'           => false,
        \'supports\'            => array( \'title\', \'comments\', \'custom-fields\' ),
        \'has_archive\'         => false,
    )
);
以下是该自定义帖子类型的自定义状态。

 register_post_status( \'inpacking\', array(
    \'label\'                     => _x( \'In Packing\', \'Order packing\' ),
    \'public\'                    => false,
    \'exclude_from_search\'       => false,
    \'show_in_admin_all_list\'    => true,
    \'show_in_admin_status_list\' => true,
    \'label_count\'               => _n_noop( \'In Packing <span class="count">(%s)</span>\', \'In Packing <span class="count">(%s)</span>\' ),
 ) );

 register_post_status( \'sent\', array(
    \'label\'                     => _x( \'Sent\', \'Order packing\' ),
    \'public\'                    => false,
    \'exclude_from_search\'       => false,
    \'show_in_admin_all_list\'    => true,
    \'show_in_admin_status_list\' => true,
    \'label_count\'               => _n_noop( \'Sent <span class="count">(%s)</span>\', \'Sent <span class="count">(%s)</span>\' ),
 ) );
最后,这里有两张图片显示了这个问题。

All showing correct total but no postsPosts shown correctly when Sent is clicked

我挠头,搜索了又搜索,我确实找到了这篇文章,但没有答案。

https://stackoverflow.com/questions/29434046/wordpress-posts-with-custom-status-need-to-show-in-all-view

我希望有人能帮助我保持理智!

CheersColin公司

1 个回复
SO网友:pck

您应该设置public 参数到true. 这样,带有“inpacking”或“sent”的帖子post_status 也将显示总计。

因此,您的代码应该如下所示:

register_post_status( \'inpacking\', array(
    \'label\'                     => _x( \'In Packing\', \'Order packing\' ),
    \'public\'                    => true,
    \'exclude_from_search\'       => false,
    \'show_in_admin_all_list\'    => true,
    \'show_in_admin_status_list\' => true,
    \'label_count\'               => _n_noop( \'In Packing <span class="count">(%s)</span>\', \'In Packing <span class="count">(%s)</span>\' ),
 ) );

register_post_status( \'sent\', array(
    \'label\'                     => _x( \'Sent\', \'Order packing\' ),
    \'public\'                    => true,
    \'exclude_from_search\'       => false,
    \'show_in_admin_all_list\'    => true,
    \'show_in_admin_status_list\' => true,
    \'label_count\'               => _n_noop( \'Sent <span class="count">(%s)</span>\', \'Sent <span class="count">(%s)</span>\' ),
) );

相关推荐