0

I am trying to add a custom post status to my custom post types using thefollowing code:

// Register new post status
function my_custom_status_creation(){
    register_post_status( 'approved', array(
        'label'                     => _x( 'Approved', 'post' ),
        'label_count'               => _n_noop( 'Approved <span class="count">(%s)</span>', 'Approved <span class="count">(%s)</span>'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true
    ));
}
add_action( 'init', 'my_custom_status_creation' );

function my_custom_status_add_in_quick_edit() {
    echo "<script>
    jQuery(document).ready( function() {
        jQuery( 'select[name=\"_status\"]' ).append( '<option value=\"approved\">Approved</option>' );      
    }); 
    </script>";
}
add_action('admin_footer-edit.php','my_custom_status_add_in_quick_edit');
function my_custom_status_add_in_post_page() {
    echo "<script>
    jQuery(document).ready( function() {        
        jQuery( 'select[name=\"post_status\"]' ).append( '<option value=\"approved\">Approved</option>' );
    });
    </script>";
}
add_action('admin_footer-post.php', 'my_custom_status_add_in_post_page');
add_action('admin_footer-post-new.php', 'my_custom_status_add_in_post_page');

The new status shows up and, although working a little bit buggy in the UI, shows up in the CP overview under it's own tab. However when I look in the REST API, the status of the post is still 'publish', thus not allowing me to filter on 'approved'. Also the WP_Query doesn't pick up 'status' => 'approved' in the args.

What am I missing here? Thanks in advance. JSON output below:

{  
    "id":799,
    "date":"2019-04-25T09:37:34",
    "date_gmt":"2019-04-25T09:37:34",
    "guid":{  
        "rendered":"xxx"
    },
    "modified":"2019-04-25T09:37:34",
    "modified_gmt":"2019-04-25T09:37:34",
    "slug":"test-123",
    "status":"publish", <-- Should be 'approved'?
    "type":"project",
    etc...

Your Answer

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

Browse other questions tagged or ask your own question.