6

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.org/Function_Reference/register_post_status

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
    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
    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
    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
    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
    Oct 9, 2012 at 20:05

4 Answers 4

11

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!

0

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.

1
  • 2
    is_admin actually returns true or false based on if you are looking at an admin screen or not. It doesn't have anything to do with your user role.
    – Matt Keys
    Oct 4, 2014 at 6:34
0

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.org/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'));
    }
});
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.