WordPress.org

Ready to get started?Download WordPress

Forums

Add new post to category (2 posts)

  1. jimfilbert
    Member
    Posted 2 years ago #

    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?

  2. christopherross
    Member
    Posted 2 years ago #

    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 );
    }

Topic Closed

This topic has been closed to new replies.

About this Topic