Wordpress-自定义帖子状态未显示
我已经创建了新的职位状态。以下是我的自定义插件中的代码:Wordpress-自定义帖子状态未显示,wordpress,post,status,Wordpress,Post,Status,我已经创建了新的职位状态。以下是我的自定义插件中的代码: add_action('init', 'new_post_status_add'); function new_post_status_add () { register_post_status('refused', array( 'label' => _x('Refused', 'post'), 'public'
add_action('init', 'new_post_status_add');
function new_post_status_add () {
register_post_status('refused', array(
'label' => _x('Refused', 'post'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Refused <span class="count">(%s)</span>', 'Refused <span class="count">(%s)</span>'),
));
}
add_action('init','new_post_status_add');
功能新建\发布\状态\添加(){
注册后状态(“拒绝”,数组(
'label'=>x('seeded','post'),
“public”=>正确,
“从搜索中排除”=>false,
“在\u管理\u所有\u列表中显示\u”=>true,
“在管理状态列表中显示”=>true,
“label_count”=>\u n_noop(“拒绝(%s)”,“拒绝(%s)”,
));
}
但它不起作用-在编辑表单和快速编辑表单中不可见:
我应该如何使状态可用?尝试使用此代码
// Register Custom Status
function custom_post_status() {
$args = array(
'label' => _x( 'Refused', 'Status General Name', 'text_domain' ),
'label_count' => _n_noop( 'Refused (%s)', ' (%s)', 'text_domain' ),
'public' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'exclude_from_search' => false,
);
register_post_status( 'refused', $args );
}
add_action( 'init', 'custom_post_status', 0 );
我希望这对你有用。很抱歉延迟回复。我希望我的评论能帮助其他人 自定义帖子状态是一个长期未解决的问题,至少从8年前在Wordpress网站上就存在了 Wordpress在codex文档中记录了函数
注册后状态()
:
此功能不会将注册帖子状态添加到管理面板中。此功能有待于将来的开发。请参阅
到考虑动作钩子
用于添加此参数
有一个工作环境,我可以用于我的一个项目。我在和中描述了混合溶液
总结是Wordpress不会自动显示自定义帖子状态。它需要使用主题的函数.php
进行操作
第一步
创建自定义帖子状态,与您提到的相同。只是,不要忘记“在‘init’操作之前不应调用此函数。”
注:以上功能不会自动选择QE中的状态,以防post的状态以前被修改过。要将selected=“true”
添加到选项中,您需要使用global$post
并检查当前状态,与下面第三步中使用的方法相同
第三步
现在,我们需要添加自定义后状态元后编辑页面也
function j_custom_status_metabox(){
global $post;
$custom = get_post_custom( $post->ID );
$status = $custom["_status"][0];
// Array of custom status messages
$arr_customstatus = array(
'refused',
'other_custom_status',
);
//Flush
$tmp = '';
foreach( $jstats as $pkey ) {
if( $status == $pkey ){
$tmp.= '<option value="'.$pkey.'" selected="true">'. $pkey .'</option>';
} else {
$tmp.= '<option value="'. $pkey .'">'. $pkey .'</option>';
}
}
echo '<script>';
echo "jQuery(document).ready( function() { jQuery( 'select[name=\"_status\"]' ).append( ". $tmp ." );
});";
echo '</script>';
}
add_action('admin_footer-post.php','j_custom_status_metabox');
add_action('admin_footer-post-new.php','j_custom_status_metabox');
注意:上面的函数不包括所有将来的自定义状态。如果需要,您需要添加
foreach
循环。尝试将PHP\u INT\u MAX
添加到您的j_custom\u post\u状态
操作中
add_action( 'init', 'j_custom_post_status', PHP_INT_MAX );
function j_custom_status_metabox(){
global $post;
$custom = get_post_custom( $post->ID );
$status = $custom["_status"][0];
// Array of custom status messages
$arr_customstatus = array(
'refused',
'other_custom_status',
);
//Flush
$tmp = '';
foreach( $jstats as $pkey ) {
if( $status == $pkey ){
$tmp.= '<option value="'.$pkey.'" selected="true">'. $pkey .'</option>';
} else {
$tmp.= '<option value="'. $pkey .'">'. $pkey .'</option>';
}
}
echo '<script>';
echo "jQuery(document).ready( function() { jQuery( 'select[name=\"_status\"]' ).append( ". $tmp ." );
});";
echo '</script>';
}
add_action('admin_footer-post.php','j_custom_status_metabox');
add_action('admin_footer-post-new.php','j_custom_status_metabox');
function j_display_status_label( $statuses ) {
global $post;
//Display label on all posts list but not on the custom status list
if( get_query_var( 'post_status' ) != 'refused' ){
if( $post->post_status == 'refused' ){
return array('Refused');
}
}
return $statuses;
}
add_filter( 'display_post_states', 'j_display_status_label' );
add_action( 'init', 'j_custom_post_status', PHP_INT_MAX );