Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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')
        return;
        $post->post_password = '';
        $visibility = 'private';
        $visibility_trans = __('Private');
    ?>
    <script type="text/javascript">
        (function($){
            try {
                $('#post-visibility-display').text('<?php echo $visibility_trans; ?>');
                $('#hidden-post-visibility').val('<?php echo $visibility; ?>');
            } catch(err){}
        }) (jQuery);
    </script>
    <?php
}

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
show 1 more comment

1 Answer 1

up vote 0 down vote accepted

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

<script type="text/javascript">
    (function($){
        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);
</script>

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
add comment

Your Answer

 
discard

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.