• Resolved Sany

    (@sannny)


    Hello all,

    I have a problem with my custom post status since I have updated WordPress to version 4.7.

    I’ve added some custom post status in my functions.php. This worked fine up to version 4.6.1. But now when I open a post (edit.php), the custom post status isn’t displayed. There is just a “Status: Edit;” If I edit the status or save the post, it is displayed correctly (Status: Archive Edit).

    I compared the html code via inspect element – the label is gone:
    WP 4.6.1:

    <div id="misc-publishing-actions">
      <div class="misc-pub-section misc-pub-post-status">
        <label for="post_status">
          ::before
          Status:
          <span id="post-status-display">Testcloud</span>
        </label>
        <span id="post-status-display"></span>
        <a class="edit-post-status hide-if-no-js" href="#post_status"></a>
        <div id="post-status-select" class="hide-if-js"></div>
        </div>
    

    WP 4.7:

    <div id="misc-publishing-actions">
      <div class="misc-pub-section misc-pub-post-status">
        ::before
        Status:
        <span id="post-status-display">Testcloud</span>
        <span id="post-status-display"></span>
        <a class="edit-post-status hide-if-no-js" href="#post_status" role="button"></a>
        <div id="post-status-select" class="hide-if-js"></div>
        </div>
    

    An example of my functions.php for adding a custom post status is:
    Register status:

    function register_custom_post_status() {
    	register_post_status('archive', array(
    		'label'						=> _x('Archive', 'page'),
    		'public'					=> true,
    		'show_in_admin_status_list'	=> true,
    		'label_count'				=> _n_noop('Archive <span class="count">(%s)</span>', 'Archive <span class="count">(%s)</span>')
    	));
    }
    add_action('init', 'register_custom_post_status');

    Add status to dropdown list in edit.php:

    function custom_post_status_submitbox_misc_actions($states) {
    	
    	global $post;
    
    	if($post->post_type == 'page') {
    		
    		if($post->post_status == 'archive') {
    			echo '<script>
    			jQuery(document).ready(function($) {
    				$("select#post_status").append("<option value=\"archive\" selected=\"selected\"> Archive </option>");
    				$(".misc-pub-section label").append("<span id=\"post-status-display\"> Archive </span>");
    			});
    			</script>';
    		}
    	}
    }
    add_action('post_submitbox_misc_actions', 'custom_post_status_submitbox_misc_actions');

    I think I need to change $(".misc-pub-section label") but I don’t know how. I tried without label $(".misc-pub-section") but then the status apears after the edit-link.

    Hopefully anyone can help me.

    saNNNy

    • This topic was modified 8 years, 2 months ago by Sany.
    • This topic was modified 8 years, 2 months ago by Sany.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    A selector like $(".misc-pub-section #post-status-display") should work, except you’ll get double content inserted because there are two elements with ID “post-status-display”. There should never be two elements with the same ID on one page. Browsers typically tolerate this but it’s considered malformed HTML and will not validate.

    You could probably use a :first-child pseudo selector instead: $(".misc-pub-section:first-child")
    The double ID should really be corrected though.

    Thread Starter Sany

    (@sannny)

    Sorry for my late answer, I wasn’t present.

    The selector $(".misc-pub-section #post-status-display") works fine. I don’t get double content but two <span class="post-status-display">.
    With $(".misc-pub-section:first-child") the status is displayed after the edit link.

    So I changed
    $(".misc-pub-section label").append("<span id=\"post-status-display\"> Archive </span>");
    to
    $(".misc-pub-section #post-status-display").append("Archive");
    which works great.

    Thank you very much!
    saNNNy

    • This reply was modified 8 years, 2 months ago by Sany.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Status Display’ is closed to new replies.