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 |4 Answers
Reset to default 12This 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
版权声明:本文标题:post status - register_post_status and show_in_admin_all_list 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745357313a2655130.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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