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.

Custom posts and custom taxonomies

  1. I will be building a site that contains a business directory and also an events directory using custom post types for each. Each post type will also have it's own custom taxonomies.
    I need 2 separate forms (one for each post type) for the user to be able to submit either an event or a directory listing.
    They also must be able to choose which categories (custom taxonomies) their event or directory listing will be in.
    Is this possible with Gravity forms?

    Posted 8 years ago on Saturday February 5, 2011 | Permalink
  2. Gravity Forms can be used to create custom post types as well as custom taxonomies, however it doesn't do so out of the box. It requires the use of available hooks to tell Gravity Forms to use a custom post type or custom taxonomy instead of the default. By default it uses standard WordPress Posts, Categories and Tags.

    So yes it is possible, but it does take some custom code. When you are ready to implement this you can search the forums for code examples as many people have done this, or you can post a new post describing what you are trying to do and request some assistance and we can assist you with basic code snippets to get you started.

    We do plan on creating an Add-On in the future that will make it much easier to create custom post types and use custom taxonomies.

    Posted 8 years ago on Saturday February 5, 2011 | Permalink
  3. Great thanks for that. Couple more questions...
    With the paypal add-on , can I create different payment options for different post types.
    For example, a users pays say $10 a year to put their listing (directory post type) in the directory section via pay to post and a user pays say $5 to list their event (event post type) for 30 days or $10 for 3 months.
    Would this be possible?

    Also, I would want to make the posts searchable by different criteria, ie. state, city, free event etc. Are all the form fields simply custom fields or will the data be stored elsewhere?

    Thanks

    Posted 8 years ago on Sunday February 6, 2011 | Permalink
  4. You could change the the total of the order based on selections made on the form; however, you could not specify a different payment type (ie product, donation, subscription) or if the payment will be a subscription, you could not specify different recurring terms. Each PayPal feed currently only handles one payment type and settings and each form can only have one PayPal feed.

    Searching through posts would be more a part of WordPress functionality than Gravity Forms. The Gravity Form just creates the posts and maintains a reference link to the created post in the entries admin.

    Gravity Forms has a Custom Post Field that can be used to store form data into a post's custom fields.

    Posted 8 years ago on Sunday February 6, 2011 | Permalink
  5. 524concepts
    Member

    Hello everyone. I am loving Gravity Forms so far! However, I'm trying to enable a custom post type's custom taxonomies on my form for a user to submit from the site. This is my code:

    function add_taxonomy_data( $form )
    {
    	if($form["id"] == '2')
    	{
    		// set the custom taxonomies
    		wp_set_object_terms( $form['11'], 'ministry_focus' );
    		wp_set_object_terms( $form['8'], 'countries' );
    	}
    }
    add_action( 'gform_post_submission', 'add_taxonomy_data' );

    However, it's still using the default Wordpress categories and tags. Any help would be greatly appreciated!

    Posted 8 years ago on Thursday February 10, 2011 | Permalink
  6. Hi Andrew,

    Give this a shot: http://pastie.org/pastes/1550503/text

    It's a good chunk of code, but it makes custom taxonomies a breeze. Instructions on use below.

    1. Paste this code into your theme's functions.php:
      http://pastie.org/pastes/1550503/text
    2. Add a "dropdown" field to your form
    3. Go to the drop down fields "Advanced" tab
    4. Click "Enable population with a taxonomy" and select your taxonomy from the dropdown: http://grab.by/8T9I
    5. Done!
    Posted 8 years ago on Thursday February 10, 2011 | Permalink
  7. 524concepts
    Member

    David... thanks very much for the help. But, it's not working for me. I have tried changing the position from 50 to 14 (that's the ID of the position of the dropdown on my form), and also tried it at 50. Is there something else I need to change in that code for my form? My form ID is 2. I've also tried putting the code in different positions of my functions.php just in case something else was throwing it off. Here's a shot of my advanced tab for the drop down:

    http://grab.by/8TWy

    Posted 8 years ago on Friday February 11, 2011 | Permalink
  8. Hi 524, I forgot to mention that you'll need to be using the latest GF RC which can be downloaded here. If you were already running this version or have installed it and this is still not working, let me know.

    Posted 8 years ago on Friday February 11, 2011 | Permalink
  9. 524concepts
    Member

    Excellent! It is working now. Is there a way for this to work with the Multiple Choice form element? Just in case my client wants to be able to select multiple categories? Thanks for your help! I really appreciate it.

    Posted 8 years ago on Friday February 11, 2011 | Permalink
  10. It was developed specifically for use with drop down fields (selects); however, theortically you should be able to make the following change to support multiple choice fields:

    var valid_types = new Array('select');

    to

    var valid_types = new Array('select', 'radio');

    Give it a go and let me know. :)

    Posted 8 years ago on Friday February 11, 2011 | Permalink
  11. I'm doing something very similar, and I got the custom taxonomy to show up as a drop down, but it's not attaching to the custom post type that is used with this form (using the update_post_type hack found elsewhere). It would seem this custom taxonomy needs to be available for the Post Fields?

    Thank you so much.

    Posted 8 years ago on Saturday February 12, 2011 | Permalink
  12. It was my bad ... got it fixed! thanks...

    Posted 8 years ago on Sunday February 13, 2011 | Permalink
  13. 524concepts
    Member

    Hey David... I should actually clarify... I said "multiple choice" in one of my posts when I meant to say that I want to use this with Checkboxes. I changed the valid types to 'checkbox' and added a checkbox field to my form. It pulls my taxonomies, but when I select one or multiple checkboxes, it either doesn't validate (I've set it as required), or doesn't attach the taxonomy to my custom post.

    RedLetter... what did you do to get it to attach to the post?

    Thanks!

    Posted 8 years ago on Monday February 14, 2011 | Permalink
  14. I'm using this approach to populate three separate taxonomies within the same post. Unfortunately it only works on the last of the three taxonomies offered. I need it to work for all three.

    More detailed description:

    The custom post type has four custom taxonomies:

    Status
    Type
    Local Office
    Municipality

    The Status taxonomy is populated automatically when the form is submitted through a separate script. It is always the same and works so we'll just ignore it.

    The three other taxonomies, type, local office and municipality all need to be selected through drop-down fields in the form. All three fields are populated properly using the code supplied by David above. However, when submitted only the last of the taxonomies retains its selection while the other two remain blank. If I move one of the blank taxonomies down so it figures after the one that was on the bottom, this new taxonomy is selected but not the two other ones.

    What makes this even weirder is that I'm using a query string to parse the data in a thank you page and this works just fine. It appears that although the data gets passed to the query string, either GravityForms or WordPress is unable to take that data and attach it to the taxonomies properly.

    This is a vital component of the site I'm working on and it is imperative that submitters can interact with all three taxonomies. I'm guessing there is some simple solution here somewhere but this is beyond my skillset.

    Any help would be much appreciated.

    Posted 8 years ago on Tuesday February 15, 2011 | Permalink
  15. @524concepts, this script really isn't setup to handle multiple taxonomies. This snippet is provided as is and is not covered by standard support. You should only need to modify the "ounce_gform_post_submission" function in the snippet to support multiple taxonomies.

    @mor10, conceptually all you would need to do is change the "false" on this line to "true". Setting this to "true" will append the taxonomy instead of replacing.

    $result = wp_set_object_terms($post_id, (int) $term_id, $taxonomy, false);

    Posted 8 years ago on Tuesday February 15, 2011 | Permalink
  16. Thanks for looking into it David. Unfortunately swapping false to true did not solve the issue.

    Since I'm not going to be adding more nor chaning my taxonomy names, is there a way I can hard-code the three taxonomies into functions.php so that they get populated properly? As far as I can tell the problem I'm having lies in GF/WP not looping through all the taxonomies but just grabbing the last one. Hard-coding the post option should bypass this problem, no?

    Posted 8 years ago on Tuesday February 15, 2011 | Permalink
  17. Hi mor10, I updated the snippet to support multiple taxonomy fields: http://pastie.org/pastes/1568148/text

    Sorry 524concepts, I took a look at adding support for check box taxonomies and unfortunately it is outside of what I can do for standard support.

    Posted 8 years ago on Tuesday February 15, 2011 | Permalink
  18. @David: I knew there was a reason I paid for the Developer Support Licence. Works like a charm. Much obliged.

    Posted 8 years ago on Tuesday February 15, 2011 | Permalink
  19. 524concepts
    Member

    David - thanks for checking on this and for all of your help. I'm really enjoying Gravity Forms so far. In this case, however, I've figured out how to use my custom post type combined with the Members plugin to accomplish exactly what I need. Thank you!

    Posted 8 years ago on Thursday February 17, 2011 | Permalink
  20. bradvin
    Member

    Hey guys, you can save to a custom post type using this plugin :

    http://wordpress.org/extend/plugins/gravity-forms-custom-post-types/

    You can also map a dropdown field to a custom taxonomy by setting the CSS class name

    Posted 8 years ago on Monday February 21, 2011 | Permalink
  21. Sbyrakis
    Member

    Hi, I intend to use the gforms within BuddyPress allowing frontend entry /editing of custom post types. Do you anticipate any problems with this?

    Posted 8 years ago on Monday February 28, 2011 | Permalink
  22. @sbyrakis Out of the box, Gravity Forms only creates posts, it doesn't edit them. So if you wanted to use Gravity Forms to also edit posts you would have to write custom code to do so.

    Posted 8 years ago on Monday February 28, 2011 | Permalink
  23. Sbyrakis
    Member

    Ok, I see. Could a newbie do this custom code or it requires significant experience in PHP/WP/BP?

    Posted 8 years ago on Monday February 28, 2011 | Permalink
  24. Post Editing is a little bit more advanced. You have to pre-populate the form with the existing values and then you have to write custom code to tell Gravity Forms to overwrite an existing post rather than create a new one. So it requires 2 areas of customization. It can all be done using API hooks without editing the plugin itself.

    If you want us to recommend a WordPress consultant with Gravity Forms customization experience to assist you with this, we can provide you with some names.

    Posted 8 years ago on Monday February 28, 2011 | Permalink
  25. Sbyrakis
    Member

    Thank you for your response, yes I would like to have your recommendation to a consultant that could help in this.

    Cheers!

    Posted 8 years ago on Monday February 28, 2011 | Permalink
  26. Here are a couple you can try contacting:

    Ounce of Talent
    http://www.ounceoftalent.com

    WebDevStudios
    http://www.webdevstudios.com

    I know Ounce of Talent has done similar types of customizations to what you described.

    Posted 8 years ago on Monday February 28, 2011 | Permalink
  27. Hi,

    I got the code found in here: here working perfectly, but I wanted to use it with multiple choice field. With the var valid_types = new Array('select', 'radio'); it does work, but you'll get the default/first choice value there as a choice in the field, the one which could read something like "Choose a category" in dropdowns.

    How could I get rid of that?

    Posted 8 years ago on Friday March 11, 2011 | Permalink
  28. Hi Tiedemies,

    Remove the code block below from the ounce_taxonomy_as_choices() function:

    switch($first_choice){
    
        // if no default option is specified, dynamically create based on taxonomy name
        case '':
            $choices[$i]['text'] = "Select a {$taxonomy->labels->singular_name}";
            $choices[$i]['value'] = "";
            $i++;
            break;
    
        // populate the first item from the original choices array
        default:
            $choices[$i]['text'] = $first_choice;
            $choices[$i]['value'] = '';
            $i++;
            break;
        }
    Posted 8 years ago on Friday March 11, 2011 | Permalink
  29. @David Smith, thank you, worked great.

    But what if I have also a dropdown field where I would need the said default value? Any way to disable it for multiple choices and enable in dropdowns? If it gets too complicated, don't sweat it, but in case there's a simple and quick solution I'd love to hear about it.

    Thanks.

    Posted 8 years ago on Friday March 11, 2011 | Permalink
  30. Give this a try: http://pastie.org/1660605

    Posted 8 years ago on Friday March 11, 2011 | Permalink
  31. @David Smith, the code worked perfectly, thank you very much!

    Posted 8 years ago on Saturday March 12, 2011 | Permalink
  32. This works well. I notice that the taxonomy terms don't populate the conditional logic drop down boxes. Any idea how to make that work?

    Posted 8 years ago on Tuesday April 12, 2011 | Permalink
  33. I've tried various things on here, but I don't seem to be gettignng anywhere.

    I'm not seeing the section that says 'Enable population with a taxonomy at all', this is all I see in the advanced section:

    http://www.theisleofavalon.com/temp.png

    I am not sure I'm filling in the bits right, maybe that's the problem. The form ID is 2 and I'm assuming the position is 30 (Firebug says field_30).

    Posted 8 years ago on Saturday April 30, 2011 | Permalink
  34. @BAWTA the "Enable population with a taxonomy" is a function of the Gravity Forms + Custom Post Type Add-On and not a built in Gravity Forms feature. So if you don't have that Add-On installed you wouldn't see that feature. That plugin can be found here:

    http://wordpress.org/extend/plugins/gravity-forms-custom-post-types/

    It is a 3rd party plugin and not one we created or support.

    Posted 8 years ago on Monday May 2, 2011 | Permalink
  35. Doh!

    Thanks

    Posted 8 years ago on Monday May 2, 2011 | Permalink
  36. twessel
    Member

    @David Smith. Hi. I got your script to work with dropdowns...is there a way to add taxonomy support for dropdowns and single line text in the sample script? Is there an extra line I can add or something simple like that? Thanks for the great support.

    Posted 8 years ago on Thursday June 23, 2011 | Permalink
  37. hioolen
    Member

    Hi, earlier i've found the custom post-type drop down, i would however like to make a dropdown that is populated by selected items in a taxonomy. i.e. i have Hotels in a custom post type, and a custom taxonomy for room types. Now i only want customers, who are on a hotel page, to be able to select room-types which are available for that hotel and not ALL the room types, which i currently get in the custom posttype drop down.....
    Hope you can help!

    Posted 8 years ago on Tuesday July 12, 2011 | Permalink
  38. stl99
    Member

    Hi,

    David's howto worked really great and I was able to successfully add a taxonomy drop down to a form. Would it also be possible to use it for conditional fields?

    Right now when selecting the taxonomy dropdown field under condotional logic no taxonomy terms are displayed...

    Cheers,
    Thomas

    Posted 7 years ago on Monday January 16, 2012 | Permalink
  39. @stl99, can you create a new topic please in the regular support forums, and reference the specific post here, so we can handle it as a regular support request, not a year-old pre-purchase topic? Thank you.

    Posted 7 years ago on Tuesday January 17, 2012 | Permalink

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