WordPress.org

Support

Support » Plugins and Hacks » Add new post to category

Add new post to category

  • jimfilbert
    Member

    @jimfilbert

    Is there a simple way to add a new post that will automatically have a category selected? Perhaps through URL parameters. Something like:

    /wp-admin/post-new.php?cat=2

    For instance, say I have a category for Video posts. I can add a link in the admin for “Add New Video” – but want it to automatically apply the correct category when going to add new post.

    Anyone ever have any luck with this?

Viewing 1 replies (of 1 total)
  • christopherross
    Member

    @christopherross

    Jim, if you always want *all* posts added to a category (the way the default one works) you could do that with a Hook.

    add_action( 'save_post', 'thisismyurl_force_category_save' );
    
    function thisismyurl_force_category_save( $post_id ) {
    
         global $post;
         $my_post = array();
         $my_post['ID'] = $post_id,
         $my_post['post_category'] = array( 32 ); // assuming 32 is the category
         wp_update_post( $my_post );
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Add new post to category’ is closed to new replies.