3

I've created a simple plugin for our WP site to allow us to enter in our products that we despatch.

To do this I've created a new Post Type called 'order_packing' and within that 2 new Post Statuses: 'In Packing', 'Sent'.

The problem I have is that list correctly shows the packing lists within the ALL (2) total - but doesn't list the packing lists. If I click the 'Sent' status then I get both shown in the list. So my issue is the data is there, but they're not showing under the ALL tab.

Here's the code that creates the Post Type, this all works perfectly

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,
    )
);

Here are the Custom Statuses for that Custom Post Type.

 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>' ),
 ) );

Finally here are two images showing the issue.

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

I'm scratching my head and have searched and searched, I did find this post but there's no answers to it.

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

I hope someone can help save my sanity!

Cheers Colin

2 Answers 2

2

You should set the public argument to true. This way the post with 'inpacking' or 'sent' post_status will also show in total.

So your code should be like this:

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>' ),
) );
1
  • Actually, setting any of the public, protected, or private arguments will work.
    – Mort 1305
    Mar 28, 2022 at 0:08
0

Old question/answer, but clarification to the question should be addressed.

First, the codex identifies the default values of both show_in_admin_all_list and show_in_admin_status_list to have a default value that is opposite of internal and the exclude_from_search as the same of internal. The doc indicates the default setting is internal=FALSE so you don't have to explicitly set it or anything related to it.

Second, though @pck is correct in that setting public=TRUE will solve the problem, there is an issue with this answer. Not only will setting public=TRUE give access to posts having this status on the front end (both in display and query), but permission issues could occur as well. Such an outcome is not acceptable in many cases, like when internal company shipping processes are not to be made available to the public or users lacking proper credentials. (I assume this is your situation as you have public=FALSE and capability_type set in your registration of the order_packing post type.) What @pck is eluding to is that the public, protected, or private argument needs to be set in order for the posts of the custom status to be displayed in the "All" view. This is because the code of WP_Query->get_posts() will only return posts having statuses registered with one of these arguments set.

With these two things in mind, a more appropriate solution to your specific circumstance would be:

register_post_status( 'inpacking', array(
    'label'                     => _x( 'In Packing', 'Order packing' ),
    'private'                   => 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' ),
    'private'                   => true,
    'label_count'               => _n_noop( 'Sent <span class="count">(%s)</span>', 'Sent <span class="count">(%s)</span>' ),
) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.