WordPress.org

Ready to get started?Download WordPress

Forums

Gravity Forms + Custom Post Types
Meta fields in an array? (10 posts)

  1. webicycoffee
    Member
    Posted 3 years ago #

    Great plugin, a huge timesaver!

    I wanted to see if there was a way to accommodate custom post types that were set up as an array rather than in separate custom fields. For example:

    • _my_meta['first_name']
    • _my_meta['last_name']

    I'd rewrite the CPT, but there's already hundreds of posts entered. Any suggestions for a hack?

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

  2. timmmmyboy
    Member
    Posted 2 years ago #

    I'm looking for the exact same functionality. I'm working with a theme that already has a ton of information populated and built in, but they use arrays instead of separate custom fields and I can't populate them from a Gravity Form. I'd love to find out how to do this!

  3. bradvin
    Member
    Plugin Author

    Posted 2 years ago #

    This can definately be done, but as you say it would require some hacking. The best way I can think of catering for this is to add a checkbox under advanced settings for the custom field. something like:

    [x] Save value to array
    Array key [___________________________]

    so when you check "save value to array" it shows another textbox "array key" where you can enter the key used in the array eg. 'first_name'

    Would something like that work for you?

  4. timmmmyboy
    Member
    Posted 2 years ago #

    I think that would definitely work. Seems a lot more elegant than the hacks I'm seeing of converting every array to individual custom fields. How difficult would it be to add the functionality?

  5. webicycoffee
    Member
    Posted 2 years ago #

    That'd definitely work. It seems like we'd have to lean on Gravity Forms for something like that, no?

  6. bradvin
    Member
    Plugin Author

    Posted 2 years ago #

    I can give it a go. Not sure if it should be part of the GF+CPT plugin though. What do you think?

  7. timmmmyboy
    Member
    Posted 2 years ago #

    Might be too edge case to build into the plugin, but if you at least knew what we could add to the code to make it happen I'd be happy with that solution. My guess is GF would never build it into their code base because of how small the likelihood is that someone would run into a situation like that, but I'd love it if we could make it work within this plugin. :)

  8. djdeejay
    Member
    Posted 2 years ago #

    Guys I have a theme that users a custom post type which has its own meta box - it appears they are setup as arrays somehow. I really need gravity forms to talk to these boxes as ive got everything else working but i need these boxes in.

    Did you ever add this option/hack to the plugin?

  9. bradvin
    Member
    Plugin Author

    Posted 2 years ago #

    we never added this option to the plugin, as it was too "edge case", but people have done this by creating their own little plugin that hooks into the GF set_post_values filter

  10. djdeejay
    Member
    Posted 2 years ago #

    Would anyone have such a plugin to share? Thats a little beyond my coding abilities and if its already been doneā€¦?

    For the record this is the code in the theme which creates the meta box in the custom post type of "portfolio". Would the set_post_values filter work for this upon first glance?

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic