Why do we need custom statuses? As always, there are many use cases. I personally used them only once — to mark products that didn’t fall into any category when importing from the Yandex Market.
Below is an example of creating a custom post status. More about all the parameters can be found in the official WordPress Codex. I just want to highlight the following points:
- The "label_count" parameter must be defined using the "_n_noop()" function.
- Unfortunately, custom statuses are not automatically shown on the post edit/create page or in the post list table (when hovering over the post title to see quick actions).
register_post_status('OUTSIDE', array(
'label' => 'Uncategorized',
'label_count' => _n_noop('Uncategorized <span class="count">(%s)</span>', 'Uncategorized <span class="count">(%s)</span>'),
'public' => true,
'internal' => true,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
));To make this work, I had to use a "workaround" I found on the internet. Specifically:
/* Called in class constructor */
add_action('admin_footer-post.php', array($this, 'admin_footer_post'));
add_action('admin_footer-post-new.php', array($this, 'admin_footer_post'));
add_action('admin_footer-edit.php', array($this, 'admin_footer_edit'))
/* Just class methods */
/**
* @hook
* - admin_footer-post.php
* - admin_footer-post-new.php
*/
public function admin_footer_post()
{
if(get_current_screen() -> post_type == 'ya-catalog'):
?>
<script>
jQuery(document).ready(function()
{
jQuery('select[name="post_status"]').append('<option value="OUTSIDE">Out of category</option>');
});
</script>
<?php
endif;
}
/**
* @hook admin_footer-edit.php
*/
public function admin_footer_edit()
{
if(get_current_screen() -> post_type == 'ya-catalog'):
?>
<script>
jQuery(document).ready(function()
{
jQuery('select[name="_status"]').append('<option value="OUTSIDE">Out of categories</option>');
});
</script>
<?php
endif;
}The solution is not the most elegant, but it’s still better than nothing.
