Skip to content

Instantly share code, notes, and snippets.

@bgoewert
Last active May 14, 2025 19:00
Show Gist options
  • Select an option

  • Save bgoewert/5dc095d9daf903d9abe8882bcf5219ff to your computer and use it in GitHub Desktop.

Select an option

Save bgoewert/5dc095d9daf903d9abe8882bcf5219ff to your computer and use it in GitHub Desktop.
Create a WordPress Custom Post Type
<?php
function custom_post_status()
{
$slug = 'unread';
$label = _x('Unread', 'post');
// check if status already exists
if (post_type_exists($slug)) {
return;
}
register_post_status($slug, [
'label' => $label,
'public' => true,
'protected' => false,
'private' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop(
"{$label} <span class=\"count\">(%s)</span>",
"{$label} <span class=\"count\">(%s)</span>",
),
]);
add_action('post_submitbox_misc_actions', function ($post) use ($slug) {
echo "<script>jQuery('#post_status').append('<option value=\"{$slug}\">{$label}</option>\');";
if ($post->post_status === $slug) {
echo "jQuery('#post-status-display').text('{$label}');";
echo "jQuery('#post_status').val('{$slug}');";
}
echo '</script>';
});
}
add_action('init', 'custom_post_status');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment