Custom post status not appearing
Asked Answered
R

5

9

I am building a directory theme for a client of mine, and I like to add the feature of expiration in the posts by modifying the post status from publish to expired.

To achieve that, I am trying to register a new post status by using the following code:

add_action('init',    'registerStatus', 0);

function registerStatus()
{
    $args = array(
        'label'                     =>  _x('Expired', 'Status General Name', 'z' ),
        'label_count'               =>  _n_noop('Expired (%s)',  'Expired (%s)', 'z'),
        'public'                    =>  true,
        'show_in_admin_all_list'    =>  true,
        'show_in_admin_status_list' =>  true,
        'exclude_from_search'       =>  true
    );

    register_post_status('expired', $args);
}

The problem is that I cannot see the registered post status either in WordPress posts, either in my custom post type post statuses.

Am I doing something wrong?

Radial answered 30/11, 2013 at 8:52 Comment(0)
B
6

Custom post status functionality is still under development (as it has been for the past four years!), see https://core.trac.wordpress.org/ticket/12706, and comments on https://wordpress.stackexchange.com/q/67655/25765. More useful info here: https://wordpress.stackexchange.com/search?q=register_post_status.

Personally, I'd strongly discourage implementing custom post statuses, but if really necessary, you could take a look at how the Edit Flow plugin handles it.

Banwell answered 30/11, 2013 at 14:12 Comment(1)
Highly recommend taking Edit Flow. I was able to easily add extra post statuses to my custom post type after spending over 1 hour making no progress with custom code!Comus
M
10

Thanks to Ryan Bayne I was able to add a custom post status to the admin panel on the edit post page. There is no wordpress filter avaiable. His solution with jQuery is perfect. Here the code if anyone else is searching for a solution:

add_action( 'post_submitbox_misc_actions', 'my_post_submitbox_misc_actions' );
    function my_post_submitbox_misc_actions(){

    global $post;

    //only when editing a post
    if( $post->post_type == 'post' ){

        // custom post status: approved
        $complete = '';
        $label = '';   

        if( $post->post_status == 'approved' ){
            $complete = 'selected=\"selected\"';
            $label = '<span id=\"post-status-display\"> Approved</span>';
        }

        echo '<script>'.
                 'jQuery(document).ready(function($){'.
                     '$("select#post_status").append('.
                         '"<option value=\"approved\" '.$complete.'>'.
                             'Approved'.
                         '</option>"'.
                     ');'.
                     '$(".misc-pub-section label").append("'.$label.'");'.
                 '});'.
             '</script>';
    }
}
Monney answered 3/12, 2014 at 13:5 Comment(1)
In WP 4.8.2 you must change the $label = '<span id=\"post-status-display\"> Approved</span>'; to $label = 'Approved'; and '$(".misc-pub-section label").append("'.$label.'");'. to '$(".misc-pub-section #post-status-display").append("'.$label.'");'.. For reference: wordpress.org/support/topic/custom-post-status-displayGerius
B
6

Custom post status functionality is still under development (as it has been for the past four years!), see https://core.trac.wordpress.org/ticket/12706, and comments on https://wordpress.stackexchange.com/q/67655/25765. More useful info here: https://wordpress.stackexchange.com/search?q=register_post_status.

Personally, I'd strongly discourage implementing custom post statuses, but if really necessary, you could take a look at how the Edit Flow plugin handles it.

Banwell answered 30/11, 2013 at 14:12 Comment(1)
Highly recommend taking Edit Flow. I was able to easily add extra post statuses to my custom post type after spending over 1 hour making no progress with custom code!Comus
F
2

This feature is still pending for future development

NOTICE: This function does NOT add the registered post status to the admin panel. This functionality is pending future development. Please refer to Trac Ticket #12706. Consider the action hook post_submitbox_misc_actions for adding this parameter.

Foliolate answered 30/11, 2013 at 15:27 Comment(0)
E
1

Now November 2014 and still issues with custom statuses. I think the original code posted is fine. Here is a video showing an issue you will run into when implementing custom post status though. There may be a workaround i.e. hooking into the posts query and doing a custom query but I've not started the research.

Screencast of posts not showing in the All table when a custom status is applied, however the posts can be found in the table view for each custom status. Click here to view short clip.

That screencast was taking while I worked on my new WTG Tasks Manager plugin. I will leave my design in the plugin as it is and hopefully it helps to encourage improvements in this area of WordPress.

For proper answer...my custom status do show on the Edit Post screen for my custom post type so that is possible. If you want to take a look at my plugins registration of custom post type and statuses go to directory "posttypes/tasks.php" and play around with a working example. Here is the plugins official page...

https://wordpress.org/plugins/wtg-tasks-manager/

Ecclesiolatry answered 18/11, 2014 at 1:9 Comment(0)
A
1

Post statuses are not displayed due to a known bug - https://core.trac.wordpress.org/ticket/12706. It can be bypassed using the plugin WP Statuses from GitHub.

  1. Install the WP Statuses plugin
  2. Modify the code accordingly:
add_action('init', 'new_post_status_add');

function new_post_status_add () {
    register_post_status('refused', array(
        'label'                     => _x('Refused', 'post'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Refused <span class="count">(%s)</span>', 'Refused <span class="count">(%s)</span>'),

        /* WP Statuses specific arguments. */
        'post_type'                   => array( 'post' ), // Only for posts!
        'show_in_metabox_dropdown'    => true,
        'show_in_inline_dropdown'     => true,
        'show_in_press_this_dropdown' => true,
        'labels'                      => array(
            'metabox_dropdown' => __( 'Refused', 'wp-statuses' ),
            'inline_dropdown'  => __( 'Refused', 'wp-statuses' ),
        ),
        'dashicon'                    => 'dashicons-archive', //if you like
    ));
}
Aeneid answered 3/1, 2024 at 15:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.