WordPress.org

Ready to get started?Download WordPress

Forums

I want to make required the user to select category for each post (3 posts)

  1. Ruwan_Geeganage
    Member
    Posted 5 years ago #

    Hi all,
    I want the user to select a category before posting new post. if he\she doesn't select an category, he cant post the new post.
    It means that category of a post is must.

    Please me on this..

    thank you.

  2. dwharrington
    Member
    Posted 5 years ago #

    Have you heard back or discovered an answer for this? I want to do the same thing.

  3. Steve Taylor
    Member
    Posted 4 years ago #

    I had to hack this client-side:

    jQuery( document ).ready( function($) {
    	if ( $( ".post-new-php form#post" ).length || $( ".post-php form#post" ).length ) {
    		$( "form#post" ).submit( function() {
    			if ( $( "ul.categorychecklist input:checked" ).length == 0 ) {
    				alert( "Please select a category for this post!" );
    				return false;
    			}
    		});
    	}
    }

    I've just added this to my custom theme's admin JS file. If you need to add this to a custom theme, if the above code is in your theme in a file called "admin.js", use this code to include it:

    function admin_js() { ?>
    	<script type="text/javascript" src="<?php echo trailingslashit( get_bloginfo( 'template_directory' ) ); ?>admin.js"></script>
    <?php }
    add_action( 'admin_footer', 'admin_js' );

    It could be easily wrapped up in a tiny plugin of course.

    I'd be interested if anyone finds a server-side method.

Topic Closed

This topic has been closed to new replies.

About this Topic