Question

I am using Gravity Forms to let users create posts. The user fills out a bunch of information, and a post is created. The user gets to choose which categories the post is in, but there is one more category that I need to add for every post. I am trying to use the gform_after_submission hook (http://www.gravityhelp.com/documentation/page/Gform_after_submission) and wp_update_post. I just want to add one more category to the post. Here is my code:

add_action("gform_after_submission_5", "add_category", 10, 2);
function add_category($entry) {
  $post = get_post($entry["post_id"]);
  $post->post_category = array ( 48 );
  wp_update_post($post);
}

This does add the appropriate category, so that's good, but it also removes ALL of the other post data, which is bad.

What am I doing wrong? Can this code be made to work, or should I be taking another approach?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top