Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Hitoshi

Bulk edit custom post status

Hi there,

By default, only “Draft”, “Scheduled”, “Pending” and “Trash” are available, but how can I add the “register_post_status” post statuses to the batch editing options?

Thanks,

3 weeks, 4 days ago
Stefan van den Dungen Gronovius
Developer

When using the Status column, I do see the available post status in the edit and bulk edit dropdown.
This is the snippet I use.

function my_custom_post_status()
{
    register_post_status('test', [
        'label'                     => 'Test',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
    ]);
}

add_action('init', 'my_custom_post_status');

Can you share your code to register the post types? Just to be sure, are you talking about the dropdown when you’re using our Inline Edit feature and not the Quick Edit feature in WordPress?

3 weeks, 4 days ago
Hitoshi

Thanks Stefan,

re is my snippet.


add_action('init', function () {
  register_post_status('test', array(
    'label'                     => 'Test'
    'label_count'               => _n_noop('Test (%s)', 'Test (%s)'),
    'public'                    => false,
    'protected'                 => false,
    'private'                   => false,
    'internal'                  => true,
    '_builtin '                 => false,
    'publicly_queryable'        => false,
    'exclude_from_search'       => false,
    'show_in_admin_all_list'    => true,
    'show_in_admin_status_list' => true,
    'date_floating'             => false,
  ) );
});

Yes, this is not the quick edit feature of WordPress.
I would like to have the custom post statuses I have added displayed in the inline edit pull-down and the bulk edit modal pull-down in the AC.

I added the WordPress quick edit pulldowns with JS.


add_action('admin_print_footer_scripts', function () {
?>
  <script>
    window.addEventListener('DOMContentLoaded', function() {
      const postStatus = document.querySelector('select[name="_status"]');
      const option = document.createElement('option');
      option.text = 'Test';
      option.setAttribute("value", "test");
      postStatus?.appendChild(option);
    });
  </script>
<?php
});
3 weeks, 3 days ago
Stefan van den Dungen Gronovius
Developer

Thanks for the input.
We specifically filter out internal taxonomies.
Is there a specific reason that you use that flag since you can probably use other flags to make it not ‘public’.
If this is needed for your website, you could also use the following hook to check for the column and add your status manually.

add_filter('acp/editing/post_statuses', function ($stati, AC\Column $column) {
    return $stati;
},10,2);
3 weeks, 3 days ago
Hitoshi

Thanks Stefan!!

Certainly there are many other ways to avoid ‘public’, but we really needed to keep track of the submission status.
I was able to solve the problem with the filter you taught me!

I will input my snippet for developers who have the same problem.


add_filter('acp/editing/post_statuses', function ($stati, AC\Column $column) {
  $stati["termination"] = (object) [
    "label"                     => "Test",
    "label_count"               => _n_noop('Test (%s)', 'Test (%s)'),
    "exclude_from_search"       => false,
    "_builtin"                  => true,
    "public"                    => false,
    "internal"                  => false,
    "protected"                 => false,
    "private"                   => false,
    "publicly_queryable"        => true,
    "show_in_admin_status_list" => true,
    "show_in_admin_all_list"    => true,
    "date_floating"             => false,
    "name"                      => "test"
  ];

  return $stati;
}, 10, 2);

It’s solved, Thank you so much!!!

3 weeks, 3 days ago
Stefan van den Dungen Gronovius
Developer

Great, thanks for letting me know.
I’ll close this topic.

3 weeks, 1 day ago

You must be logged in to reply to this topic.