Custom Post Type Statuses

I’m (still) working on a custom post type plugin for my workplace and came across an easier method of marking Visitors (my custom post type) as either “Here” (aka checked-in) or “Not Here” (not checked-in).

I’ve explored the Edit Flow plugin and, to be honest, I can’t really follow what all is going on here… I did however come across a function that appears to be in WordPress’ core, but I can’t seem to find much documentation on the web (none on wordpress.org even). The function is register_post_status but the best I found was this resource which at best only shows me the arguments that go with the function’s $args parameter.

Read More

Anyone ever tried this? Or am I the only one who’s really needed custom post statuses for custom post types?

EDIT: I’ve read this and this as per the answers/comments I’ve received. Here is an implementation that I’m not 100% sure about because documentation is lacking.

I know it doesn’t work, but I don’t get why it doesn’t work. Neither of the two statuses show up in the status list. My next course of action is to hack it with a taxonomy and just create my own ‘Publish’ meta box.

    register_post_status('in', array(
            'label' => _x( 'Logged In', $post_type ),
            'protected' => true,
            'label_count' => _n_noop( 'Visitors logged in <span class="count">(%s)</span>', 'Visitors logged in <span class="count">(%s)</span>' ),
            'show_in_admin_status_list' => true,
        ));

    register_post_status('out', array(
            'label' => _x( 'Logged Out', $post_type ),
            'protected' => true,
            'label_count' => _n_noop( 'Visitors logged out <span class="count">(%s)</span>', 'Visitors logged out <span class="count">(%s)</span>' ),
            'show_in_admin_status_list' => true,
        ));

Related posts

Leave a Reply

2 comments

  1. Custom post statuses do exist in the core code of WordPress, so you can register them, but they are not yet properly implemented in the admin screens (e.g. they don’t show in the dropdown list of statuses alongside Pending Review, Draft, Published). So essentially you can do very little with them at the moment.

    You can read more on Trac ticket 12706.

  2. I have done something similar to what facebook does, like where you can post status updates. Similar to what you’re trying to do i believe. I just created a custom post type that had the supported the excerpt and title only, to use it for posting the statuses.

    The register_post_status is not what you think it is. The post statuses in wp are things like, publish, draft, future (scheduled posts) and locked/private. They are the statuses of your posts. Whether they are published or not, whatever they may be set as.

    To show who’s currently logged in/out you could use a plugin for that. I recommend this one for example. http://lesterchan.net/portfolio/programming/php/#wp-useronline

    You could also create a relatively short script that loops through all registered users, and checks if is_user_logged_in() by their IDs. This wouldn’t work to return the users who are logged in, it just loops through all the registered users so you can do stuff with them. You could figure out a way to make it check is_user_logged_in() though somehow I’m sure.

    <?php
    $wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
    
    foreach ( $wp_user_search as $userid ) {
        $user_id = (int) $userid->ID;
    
        /* use this or some other current_user() function in WP to check if user is logged 
           @is_user_logged_in();
        */
    }
    ?>