WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been following the advice of this answer, but ran into a glitch...

The post Visibility says "Private" on my custom post, but if you click the "Edit" link to reveal the radio buttons, the "Public" button is still selected (see screen shot). So in fact my post is not private at all, even though it says that word in the visibility field (so appears to be working at first glance).

Here is what my code looks like **Edits: this was changed to show the correct code:

// Set Updates post to private by default

add_action( 'post_submitbox_misc_actions' , 'wpse118970_change_visibility_metabox' );
function wpse118970_change_visibility_metabox(){
    global $post;
    if ($post->post_type != 'updates')
        $post->post_password = '';
        $visibility = 'private';
        $visibility_trans = __('Private');
    <script type="text/javascript">
            try {
                $('#post-visibility-display').text('<?php echo $visibility_trans; ?>');
                $('#hidden-post-visibility').val('<?php echo $visibility; ?>');
            } catch(err){}
        }) (jQuery);

Any suggestions?

*Note: I commented out the print_r($post); because it was giving me extra text on my page that I didn't want my client looking at (see screen shot). I also removed the call to show the message, as I didn't want to draw attention to it. Guess I could have also removed that code to clean it up, but hadn't thus far.

share|improve this question
I double checked that just now, and even created a new updates custom post to see the process from scratch, and it still is having the same issue. The text says "Private", but the radio button says "Public". Is there any other code that I need to add besides what I've posted above (perhaps I missed that part in the previous conversation)? – jen_f Dec 6 '13 at 0:29
I really liked your code (and want it to work so badly) because a different code that I had been using previously was giving me tons of headaches -- couldn't trash any posts, auto drafts were publishing. I was happy to remove that code! Yours is such a nice solution -- if only I could get it to work as it should! – jen_f Dec 6 '13 at 0:31
Sorry, you're right about what you're experiencing. The reason it worked for me must because the old code was in there before, messy dev environment. Give me a minute and I give you an answer. – ialocin Dec 6 '13 at 0:40
I found an answer!! I added this code to the javascript and it worked: $('#visibility-radio-<?php echo $visibility; ?>').attr('checked', true); – jen_f Dec 6 '13 at 0:42
Updated code listed above. Works :) Thanks for giving me the bones to get this solution working! – jen_f Dec 6 '13 at 0:46
up vote 0 down vote accepted

Actually all you have to do is changing the script part to this:

<script type="text/javascript">
        try {
            $('#post-visibility-display').text('<?php echo $visibility_trans; ?>');
            $('#hidden-post-visibility').val('<?php echo $visibility; ?>');
            $('#visibility-radio-<?php echo $visibility; ?>').attr('checked', true);
        } catch(err){}
    }) (jQuery);

You see there is an additional line compared to your code. I'm referring you to my original answer for more information, this is element of the second - 2. - part of the answer.

share|improve this answer
yes - that was also the solution I found. Thanks so much for all of your help!!! Love this code! – jen_f Dec 6 '13 at 0:46
Thanks, my pleasure. @jen_f – ialocin Dec 6 '13 at 0:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.