Reputation: 55
I created a custom status "Expired" for a custom post type (made with Pods). It's working fine except in the admin the posts with the custom status "Expired" are not showing up in the All listing, they are showing up only in the "Expired" status listing.
This is the code I am using to add the status in my 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' );
Any help how I can fix that would be much appreciated.
Upvotes: 1
Views: 157
Reputation: 71
I think this is because you have set the expired post status as public => false. Can you try and change it to true?
Here's a code, if you only wish the public setting to be true in admin:
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');
Upvotes: 1