How to Add a Custom Post Status to Quick Edit

I think you can find a lot of good information about status creation in WP. But I didn’t find any notes about how to add a status (custom status, you just created) into inline post edit: So, I mean this dropdown list: As you can see, there are only 4 WordPress default common statuses. And […]

#wp-admin  /   3

I think you can find a lot of good information about status creation in WP. But I didn’t find any notes about how to add a status (custom status, you just created) into inline post edit:

inline quick edit in WordPress

So, I mean this dropdown list:

Post Statuses In WordPress Quick Edit

As you can see, there are only 4 WordPress default common statuses. And when you create your own status with register_post_status() function, it won’t appear there.

function rudr_custom_status_creation(){
	register_post_status( 'featured', array(
		'label'                     => _x( 'Featured', 'post' ), // I used only minimum of parameters
		'label_count'               => _n_noop( 'Featured <span class="count">(%s)</span>', 'Featured <span class="count">(%s)</span>'),
		'public'                    => true
	));
}
add_action( 'init', 'rudr_custom_status_creation' );

Okay, let’s stop talking and start doing this. I want to show you the code which allows you to add your custom post status into quick edit dropdown.

add_action('admin_footer-edit.php','rudr_status_into_inline_edit');
 
function rudr_status_into_inline_edit() { // ultra-simple example
	echo "<script>
	jQuery(document).ready( function() {
		jQuery( 'select[name=\"_status\"]' ).append( '<option value=\"featured\">Featured</option>' );
	});
	</script>";
}

Some comments for the code:

  • Insert it to you theme functions.php file. If you know what to do — insert it anywhere you want.
  • For beginners — if your functions.php is empty, first of all add on the first line: <?php.
  • 1-3. admin_footer-edit.php action hook means that the code will be processed only on Post wp-admin/edit.php, Pages wp-admin/edit.php?post_type=page and Custom Post Type pages wp-admin/edit.php?post_type={custom post type} in administration area.
  • 6. Is anybody noticed that I didn’t use jQuery each() function? But why? Because quick edit HTML template just one for all posts.
WordPress inline post edit with you custom status in dropdown

I also recomment you to add the following hook into your functions.php to display the custom post status label like this:

custom post status label in WP

The code:

function rudr_display_status_label( $statuses ) {
	global $post; // we need it to check current post status
	if( get_query_var( 'post_status' ) != 'featured' ){ // not for pages with all posts of this status
		if( $post->post_status == 'featured' ){ // если статус поста - Архив
			return array('Featured'); // returning our status label
		}
	}
	return $statuses; // returning the array with default statuses
}
 
add_filter( 'display_post_states', 'rudr_display_status_label' );

That’s it. Please leave comment if you have a question.

Thanks for reading.

Only the best of WordPress

Subscribe to this weekly newsletter to receive the latest blog posts by email.I respect your privacy. Your email is safe with me.

Comments 3

  • Jorge Rivera September 22, 2015 at 08:57

    You are missing the part where you select the right value for the new status, you might wanna check teh step 4 of this tutorial for that! http://shibashake.com/wordpress-theme/expand-the-wordpress-quick-edit-menu

  • Thanks! This is EXACTLY what I was looking for and seems to work for me just fine (not sure about what Jorge’s comment is regarding so maybe I missed something). By the way, I am combining this with code I found to add the custom post status to the regular edit screen as well. (ref: http://stackoverflow.com/questions/20298346/custom-post-status-not-appearing)

  • thanks ,I think it is problem of wordpress

Leave your question or feedback

phpjsHTMLCSSSQLCode
Please, enter a comment
Please, enter a name
Incorrect email