I'm trying using Gravity Forms and allow for a user to submit a post to my CPT, and choose an optional Connected Post Type.

I have two CPTs, CPT1 and CPT2.

When they're viewing my form for creating a post under CPT1, I want them to be able to choose an associated post that's under CPT2.

I've been following Travis Smith's instructions on creating a custom field, which has gone pretty smoothly.

However, I'm trying to follow the Posts 2 Posts documentation about adding custom admin boxes.

I'm not sure where to start and how to achieve what I'm looking to accomplish.

Any advice?


Not sure if you really need to use the custom admin boxes, unless you need to customize labels, etc...

function my_connection_types() {
    // Make sure the Posts 2 Posts plugin is active.
    if ( !function_exists( 'p2p_register_connection_type' ) )

    p2p_register_connection_type( array(
        'name' => 'cpt1_to_cpt2',
        'from' => 'cpt1',
        'to' => 'cpt2',
            'admin_box' => 'from',
    'fields' => array(
        'field_name' => 'field_title',
        'field_name2' => 'field_title2'
    ) );
add_action( 'wp_loaded', 'my_connection_types' );

And if you need to add custom labels, you can just extend the registration array to include:

 'from_labels' => array(
      'singular_name' => __( 'Person', 'my-textdomain' ),
      'search_items' => __( 'Search people', 'my-textdomain' ),
      'not_found' => __( 'No people found.', 'my-textdomain' ),
      'create' => __( 'Create Connections', 'my-textdomain' ),

Then, to update a form field in Gravity Forms based on the connection, you can use the gform_pre_render filter to populate your field; something like:

http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields http://www.gravityhelp.com/documentation/page/Gform_pre_render

Short on time, but if I get a chance I'll update with a more specific Posts2Posts example. I'm sure if you dig into his admin box class a bit, you'll be able to combine it with the filter above to get the results your looking for.

| improve this answer | |
  • Hey Gil, thanks for the response. I've seen those docs and been able to use them successfully in a regular theme circumstance, but the issue I'm having is trying to integrate it into Gravity Forms. I'm trying to create a custom field using the above connectors. Any thoughts how I can get that AJAX CPT<->CPT connector available as a custom field in Gravity Forms? – Jon Dingman Aug 8 '12 at 3:01
  • Updated the answer a bit -- the docs referenced should give you a solid idea of how to apply the filter to your Gravity Form, but you'll probably need to dig into the code / docs for Posts2Posts on how to pull an array of all relatable posts. – FlashingCursor Aug 9 '12 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.