admin管理员组

文章数量:1422029

I have a custom post status which should be public visible but not displayed in the "all" list of the edit screen.

This is how I register the post status:

register_post_status('my_custom_post_status', array(
    'label' => __('The Label', 'domain'),
    'public' => true,
    'exclude_from_search' => true,
    'show_in_admin_all_list' => false,
    'label_count' => //blablabla
));

The show_in_admin_all_list = false should hide the status in the all-list but it doesn't. Only if I set the public to false it is not visible. But I need public = true!

Any ideas

Codex:

I have a custom post status which should be public visible but not displayed in the "all" list of the edit screen.

This is how I register the post status:

register_post_status('my_custom_post_status', array(
    'label' => __('The Label', 'domain'),
    'public' => true,
    'exclude_from_search' => true,
    'show_in_admin_all_list' => false,
    'label_count' => //blablabla
));

The show_in_admin_all_list = false should hide the status in the all-list but it doesn't. Only if I set the public to false it is not visible. But I need public = true!

Any ideas

Codex: http://codex.wordpress/Function_Reference/register_post_status

Share Improve this question asked Oct 9, 2012 at 17:53 XaverXaver 1,0393 gold badges13 silver badges29 bronze badges 5
  • register_post_status is not! meant to be used by themes or plugins. I wrote a pretty intense plugin to work around that fact, but anyway: It's not that simple and you will simply have to drop the idea of custom post status. Search through my answers to read more about it. – kaiser Commented Oct 9, 2012 at 18:58
  • What exactly do you mean!? I've already incorperate custom stati in my plugin and have no problems. You have to many answers to look through. Any specific one? – Xaver Commented Oct 9, 2012 at 19:07
  • You will have to search on your own, but to sum it up: The post status is hard coded in lots of cases in core and even when this works in some cases, it will simply crash in others. Believe me: I digged a lot in core and you'll be surprised, where the post status is used. And you're missing lots of cases when just throwing and additional status in. Hint: The post status API is not finalized since WP 3.0 - you can see this in the incomplete phpDocBlocks and read on wp-hackers about it. – kaiser Commented Oct 9, 2012 at 19:28
  • Yes I found them missing in the quick edit section for instance and on some other places. I did some workaround in two or three cases so should not a big deal to "fix" this on later version – Xaver Commented Oct 9, 2012 at 19:43
  • Do whatever you want, I already stated that you'll run into problems - incl. the fact that the API is already started and will be finished with some version. Prepare to hit the wall ;) ... and rebuild everything (incl. fixing everything in your DB) with a future version. – kaiser Commented Oct 9, 2012 at 20:05
Add a comment  | 

4 Answers 4

Reset to default 12

This solves my problem:

register_post_status('my_custom_post_status', array(
    'label' => __('The Label', 'domain'),
    'public' => !is_admin(),
    'exclude_from_search' => true,
    'show_in_admin_all_list' => false,
    'label_count' => //blablabla
));

!is_admin() makes the status only public on the frontpage.

If you find a better solution please post it here!

My approach, inspired by @revaxarts, is this:

if (is_admin() && $_GET['post_type'] == 'post') {
  $makepublic = true;
} else {
  $makepublic = false;
}

register_post_status( 'suspended', array(
      'label'                     => _x( 'suspended', 'Status General Name', 'myadvert' ),
      'public'                    => $makepublic,
      'exclude_from_search'       => true,
      'show_in_admin_all_list'    => true,
      'show_in_admin_status_list' => true,
      'label_count'               => _n_noop( 'Suspended <span class="count">(%s)</span>', 'Suspended <span class="count">(%s)</span>' )
 ) );

Because I do not want it to see those post on the frontend while I am logged in as admin.

If you don't want to change the public parameter, because you want to have more control over your posts, you should also hook the pre_get_posts action to change the main query:

/**
 * Display all posts on edit.php
 * Bug fix: the 'show_in_admin_all_list' argument for the 'register_post_status' function is ignored when the argument 'public' is set to 'false'
 * @link https://core.trac.wordpress/ticket/24415
 */
add_action('pre_get_posts', function($query) {
    global $pagenow;

    if (!is_admin() || $query->query['post_type'] != 'YOUR_CPT' || $pagenow != 'edit.php') {
        return;
    }

    if (!isset($_GET['post_status']) || empty($_GET['post_status']) || (isset($_GET['post_status']) && $_GET['post_status'] == 'all')) {
        $query->set( 'post_status', array('publish', 'draft', 'foo', 'bar'));
    }
});

i am using publish press plugin to create a custom post status i changed the all post status into public, using this

register_post_status(
  $status->slug,
  [
    'label'       => $status->name,
    'public'   => true,
    'exclude_from_search'       => true,
    'show_in_admin_all_list'    => true,
    'show_in_admin_status_list' => true,
    '_builtin'    => false,
    'label_count' => _n_noop("{$status->name} <span class='count'>(%s)</span>","{$status->name} <span class='count'>(%s)</span>"),
  ]
);

all post shown at front end but edit.php all post page not working it not showing the all the post which is relevant to custom post type and it also affected the woocommerce

本文标签: post statusregisterpoststatus and showinadminalllist