自定义帖子状态未显示

 小song喪_774 发布于 2023-02-13 17:50

我正在为我的客户构建目录主题,我喜欢通过将帖子状态从发布修改为过期来在帖子中添加过期功能.

为此,我尝试使用以下代码注册新的帖子状态:

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帖子中的已注册帖子状态.

难道我做错了什么?

2 个回答
  • 感谢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>';
        }
    }
    

    2023-02-13 17:52 回答
  • 自定义帖子状态功能仍处于开发阶段(过去四年一直在发布!),请参阅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插件如何处理它.

    2023-02-13 17:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有