PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Hidden category and visible category

  1. I have a form that lets visitors create a post. I want them to be able to choose what categories the post is in, but each post also needs to go into two additional categories. So have a Post Category field where people can check boxes for the category they want. I also have an admin-only field that should add the post to the two non-optional categories, but that field doesn't seem to be working - the post doesn't get saved in that category. I assume this is because I can't have two post category fields. So is there any way I can let users choose from a bunch of categories, but also force the post to have a few other categories?

    Posted 11 years ago on Tuesday March 19, 2013 | Permalink
  2. David Peralty

    You would have to write some PHP to grab the currently selected categories, and edit the post category to append your own using the following hook: http://www.gravityhelp.com/documentation/page/Gform_post_data

    Posted 11 years ago on Tuesday March 19, 2013 | Permalink
  3. Can you provide a code example for you I would append categories? (Actually, it's a custom taxonomy.) The code examples make it clear how to change fields, but appending a category is more complicated.

    Posted 11 years ago on Tuesday March 19, 2013 | Permalink
  4. You can use the gform_after_submission hook http://www.gravityhelp.com/documentation/page/Gform_after_submission to update the post immediately after it's created. Your function would call the WordPress function wp_update_post http://codex.wordpress.org/Function_Reference/wp_update_post#Categories and you would pass in an array of category IDs.

    Posted 11 years ago on Thursday March 21, 2013 | Permalink
  5. When I do this, it erases all of the form data except for the category. Here's my code:
    http://pastie.org/7143646
    Any idea what I'm doing wrong?

    Thanks for your help!

    Posted 11 years ago on Wednesday March 27, 2013 | Permalink
  6. I fixed it. I needed to use wp_set_post_terms instead.

    Posted 11 years ago on Wednesday March 27, 2013 | Permalink
  7. Thank you for the update.

    Posted 11 years ago on Sunday March 31, 2013 | Permalink

This topic has been resolved and has been closed to new replies.