How To Add A Post To Wordpress Blog Nexcess
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 when you create your own status withregister_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 whichallows 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 Postwp-admin/edit.php
, Pageswp-admin/edit.php?post_type=page
and Custom Post Type pageswp-admin/edit.php?post_type={custom post type}
in administration area. -
6
. Is anybody noticed that I didn't use jQueryeach()
function? But why? Because quick edit HTML template just one for all posts.
I also recomment you to add the following hook into yourfunctions.php
to display the custom post status label like this:
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.
Misha Rudrastyh
I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.
Need some developer help? Contact me
Follow me on Twitter
How To Add A Post To Wordpress Blog Nexcess
Source: https://rudrastyh.com/wordpress/custom-post-status-quick-edit.html
Posted by: mooretaks1965.blogspot.com
0 Response to "How To Add A Post To Wordpress Blog Nexcess"
Post a Comment