Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom post status not appearing

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?

like image 526
KodeFor.Me Avatar asked Nov 30 '13 08:11

KodeFor.Me


People also ask

How do I create a custom post status?

On the post edit screen, click on the 'Edit' link next to status option under the 'Publish' meta box. This will reveal a drop-down menu showing all post statuses that you can select including the custom post status you just created.

What is difference between post and custom post?

Only “posts” are in the main default RSS feed but WordPress automatically builds an RSS feed for each taxonomy item and each CPT. Custom Page Templates are special files for WordPress that control how content will be displayed. They are used only with pages in WordPress, not with posts or CPTs.

What is difference between post and custom post in WordPress?

Both are ways of telling WordPress how your content should appear. The results you get by using both will vary based on your theme and plugins. Custom post types are extra options for creating WordPress content, while post formats are different ways of styling blog posts.


4 Answers

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>';
    }
}
like image 91
jlooooo Avatar answered Oct 16 '22 03:10

jlooooo


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.

like image 44
diggy Avatar answered Oct 16 '22 02:10

diggy


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.

like image 24
Trishul Avatar answered Oct 16 '22 03:10

Trishul


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/

like image 39
Ryan Bayne Avatar answered Oct 16 '22 02:10

Ryan Bayne