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.

Using gform_post_submission and usermeta

  1. I must be using this hook incorrectly, but I can't figure out how to fix it. I have two forms: one for registered users (id=1) and one for non-registered users (id=3).

    For form #3, I'm using the Gravity Forms + Custom Post Type plugin to add a dropdown field connected to a taxonomy called Gender. This way the non-registered user can select their gender and it is associated with the post.

    Registered users already have gender attached to usermeta (added during signup). When a registered user fills out form #1 I want it to use their usermeta to set the gender taxonomy.

    add_action('gform_post_submission_1', 'be_add_gender', 10, 2);
    function be_add_gender($entry, $form){
    		$data = wp_get_current_user();
    		$gender = ( 'male' == $data->gender ) ? 'male' : 'female';
    		wp_set_post_terms( $entry['post_id'],  array( $gender ), 'gender' );

    Even if my usermeta isn't set, $gender defaults to female and it should be placing the post in the 'female' term of the 'gender' taxonomy. When a post is published, no taxonomy terms are selected.

    Posted 12 years ago on Friday September 2, 2011 | Permalink
  2. It appears that you're using the hook correctly and it makes sense to me.

    Should array ($gender) just be $gender, since it's just a string, not an array? Have you already tried it like that? Or should an array of just one string work just as well?

    Other troubleshooting ideas I had:
    If you dump the $data object, what does it look like?

    What does wp_set_post_terms return (can you check the value?)

    Is the taxonomy hierarchical? (I'm guessing it's not, but I think hierarchical ones need to be passed in by ID not $string to eliminate ambiguity.)

    Posted 12 years ago on Saturday September 3, 2011 | Permalink
  3. Ah, sending the term ID instead of slug did it!

    Of course now I just went to the Codex to add that useful piece of information and it's already on there.

    Thanks for helping me troubleshoot this.

    Posted 12 years ago on Saturday September 3, 2011 | Permalink
  4. Outstanding. Glad you were able to resolve that.

    Posted 12 years ago on Saturday September 3, 2011 | Permalink

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