我为自定义帖子类型(使用 Pod 制作)创建了自定义状态“已过期”。它工作正常,除了在管理中具有自定义状态“已过期”的帖子未显示在“所有”列表中,它们仅显示在“已过期”状态列表中。
这是我用来在我的functions.php中添加状态的代码:
/**************************************************/
/* ADD EXPIRED POST STATUS */
/**************************************************/
function custom_post_status_expired(){
register_post_status( 'expired', array(
'label' => _x( 'Expired', 'post' ),
'public' => false,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>' ),
) );
}
add_action( 'init', 'custom_post_status_expired' );
function add_to_post_status_dropdown()
{
global $post;
if($post->post_type != 'job_posting')
return false;
$status = ($post->post_status == 'expired') ? "jQuery( '#post-status-display' ).text( 'Expired' ); jQuery('select[name=\"post_status\"]' ).val('expired');" : '';
echo "<script>jQuery(document).ready( function() { jQuery( 'select[name=\"post_status\"]' ).append( '<option value=\"expired\">Expired</option>' );".$status."});</script>";
}
add_action( 'post_submitbox_misc_actions', 'add_to_post_status_dropdown');
function custom_status_add_in_quick_edit() {
global $post;
if($post->post_type != 'job_posting')
return false;
echo "<script>jQuery(document).ready( function() {jQuery( 'select[name=\"_status\"]' ).append( '<option value=\"expired\">Expired</option>' );});</script>";
}
add_action('admin_footer-edit.php','custom_status_add_in_quick_edit');
function display_archive_state( $states ) {
global $post;
$arg = get_query_var( 'post_status' );
if($arg != 'expired'){
if($post->post_status == 'expired'){
echo "<script>jQuery(document).ready( function() {jQuery( '#post-status-display' ).text( 'Expired' );});</script>";
return array('Expired');
}
}
return $states;
}
add_filter( 'display_post_states', 'display_archive_state' );
如果我能解决这个问题,我将不胜感激,谢谢:-)
我认为这是因为您将过期帖子状态设置为 public => false。 你能试着把它改成 true 吗?
这里有一个代码,如果您只希望管理中的公共设置为真:
function custom_post_status_expired() {
$is_admin = is_admin(); // Check if we are in the admin area
// Define the 'public' value based on whether we are in the admin area
$public = $is_admin ? true : false;
register_post_status('expired', array(
'label' => _x('Expired', 'post'),
'public' => $public,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>'),
));
}
add_action('init', 'custom_post_status_expired');