我正在为我的客户构建目录主题,我喜欢通过将帖子状态从发布修改为过期来在帖子中添加过期功能.
为此,我尝试使用以下代码注册新的帖子状态:
add_action('init', 'registerStatus', 0); function registerStatus() { $args = array( 'label' => _x('Expired', 'Status General Name', 'z' ), 'label_count' => _n_noop('Expired (%s)', 'Expired (%s)', 'z'), 'public' => true, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'exclude_from_search' => true ); register_post_status('expired', $args); }
问题是我无法在自定义帖子类型的帖子状态中看到WordPress帖子中的已注册帖子状态.
难道我做错了什么?
感谢Ryan Bayne,我能够在编辑帖子页面的管理面板中添加自定义帖子状态.没有wordpress过滤器可用.他使用jQuery的解决方案非常完美.这里是代码,如果其他人正在寻找解决方案:
add_action( 'post_submitbox_misc_actions', 'my_post_submitbox_misc_actions' ); function my_post_submitbox_misc_actions(){ global $post; //only when editing a post if( $post->post_type == 'post' ){ // custom post status: approved $complete = ''; $label = ''; if( $post->post_status == 'approved' ){ $complete = 'selected=\"selected\"'; $label = '<span id=\"post-status-display\"> Approved</span>'; } echo '<script>'. 'jQuery(document).ready(function($){'. '$("select#post_status").append('. '"<option value=\"approved\" '.$complete.'>'. 'Approved'. '</option>"'. ');'. '$(".misc-pub-section label").append("'.$label.'");'. '});'. '</script>'; } }
自定义帖子状态功能仍处于开发阶段(过去四年一直在发布!),请参阅https://core.trac.wordpress.org/ticket/12706,并对https://wordpress.stackexchange.com发表评论/ q/67655/25765.更多有用的信息:https://wordpress.stackexchange.com/search?q = register_post_status.
就个人而言,我强烈反对实施自定义帖子状态,但如果真的有必要,你可以看一下Edit Flow插件如何处理它.