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.

Default Post Category AND Category Selection field form

  1. Great hooks and documentation!

    I wanted to post a solution to a process we are putting into place. I hope it helps someone!

    We are using a form to gather post submissions. We wanted the user to be able to select a category, but we also wanted to force submission into a particular category. When we add the category selection field to the form, the ability to add a default category is removed from the form options.

    This worked:

    add_filter("gform_post_data", "change_cat", 10, 2);
    function change_cat($post_data, $form) {
    	//Set the ID for the form you wish to execute this function
    	$form_id = 1;
    	//Set the ID for the Category you wish to
    	$cat_id = 1;
    	if($form["id"]==$form_id) {
    		array_push($post_data[post_category], $cat_id);
    	}
    	return $post_data;
    }

    If you have another way to do this, I'd love to know!

    Posted 13 years ago on Friday April 29, 2011 | Permalink
  2. The default post category is only an option on the Post Title and Post Body fields if NO Post Category field exists ont he form.

    If you want to pre-define a default category AND have category selections then the solution is fairly simple.

    - Add a Post Category Field
    - Edit the Post Category Field
    - Select Selected Category and pick ONE category, the one you want to make the default
    - Select the Advanced Tab
    - Set the Visibility for this field to Admin Only

    Now when the form is submitted, even though that Post Category field is set to admin only it will still be executed and the single category you selected for that drop down field wil be populated.

    Posted 13 years ago on Friday April 29, 2011 | Permalink
  3. Clever.

    Thanks Carl

    Posted 13 years ago on Friday April 29, 2011 | Permalink
  4. yoavadler
    Member

    Hi Carl

    Just wanted to understand: the code you wrote should be in function.php

    Tnx
    Yoav

    Posted 13 years ago on Monday May 2, 2011 | Permalink
  5. @yoavadler My example above didn't use any custom code. So i'm not sure what you are referring to.

    Posted 13 years ago on Monday May 2, 2011 | Permalink
  6. yoavadler
    Member

    I was referring to C.Bliss code, but i already managed to use the filters methods written on functions.php file

    Posted 13 years ago on Tuesday May 3, 2011 | Permalink