“注册帖子状态”;“合计”;对于自定义职位类型;配方:
register_post_status( \'aggregated\', array(
\'label\' => _x( \'Aggregated \', \'post status label\', \'plugin-domain\' ),
\'public\' => true,
\'label_count\' => _n_noop( \'Aggregated s <span class="count">(%s)</span>\', \'Aggregated s <span class="count">(%s)</span>\', \'plugin-domain\' ),
\'post_type\' => array( \'recipes\' ), // Define one or more post types the status can be applied to.
\'show_in_admin_all_list\' => true,
\'show_in_admin_status_list\' => true,
\'show_in_metabox_dropdown\' => true,
\'show_in_inline_dropdown\' => true,
\'dashicon\' => \'dashicons-businessman\',
) );
在“中”;“配方”;自定义帖子编辑屏幕的发布元框,在下拉列表中添加自定义帖子状态并更改;“保存草稿”;按钮标签,如果选定的帖子状态为;聚合(&Q):
add_action(\'admin_footer-post.php\',function(){
global $post;
$complete = \'\';
$label = \'\';
if($post->post_type == \'recipes\') {
if ( $post->post_status == \'aggregated\' ) {
$complete = \' selected=\\"selected\\"\';
$label = \'Aggregated\';
}
$script = <<<SD
jQuery(document).ready(function($){
$("select#post_status").append("<option value=\\"aggregated\\" \'.$complete.\'>Aggregated</option>");
if( "{$post->post_status}" == "aggregated" ){
$("span#post-status-display").html("$label");
$("input#save-post").val("Save Aggregated");
}
var jSelect = $("select#post_status");
$("a.save-post-status").on("click", function(){
if( jSelect.val() == "aggregated" ){
$("input#save-post").val("Save Aggregated");
}
});
});
SD;
echo \'<script type="text/javascript">\' . $script . \'</script>\';
}
});
在自定义帖子管理网格的快速编辑屏幕中添加自定义帖子状态:
add_action(\'admin_footer-edit.php\',function() {
global $post;
if( $post->post_status == \'recipes\' ) {
echo "<script>
jQuery(document).ready( function() {
jQuery( \'select[name=\\"_status\\"]\' ).append( \'<option value=\\"aggregated\\">Aggregated</option>\' );
});
</script>";
}
});
在自定义帖子管理网格中显示自定义帖子状态合计:
add_filter( \'display_post_states\', function( $statuses ) {
global $post;
if( $post->post_type == \'recipes\') {
if ( get_query_var( \'post_status\' ) != \'aggregated\' ) { // not for pages with all posts of this status
if ( $post->post_status == \'aggregated\' ) {
return array( \'Aggregated\' );
}
}
}
return $statuses;
});