Support Forum » User Profile

Forum Replies Created

Viewing 16 post (of 16 total)
  • Author
    Posts
  • in reply to: Prepopulate relationship field with current post id #33363
    esmroscesmrosc
    Participant

    Hi, This was exactly what I was also looking for and I got it working. Thank you. However I would like to add an extra part to it, so that if you wished to edit the details of the post on the front end, on the generated post, it would not then attach its own Post ID to the relationship field again.

    ie, I have 'clients' and 'equipment' as my related custom post types. when on a 'client' cpt i have the front end form to register new equipment that is related and linked to them. That is using the post id relationship code that you have provided here. But I also wish to be able to edit the equipment details using the front end form, and to do this I had the edit form on the 'equipment' post type.

    What I then realised is that the post id of the equipment that was being edited was then also being added to the same relationship field. I must only have 1 post id in this field as I use the value to link 'gravity form' submissions back to the 'client' that relate to the 'equipment'.

    I was imagining that perhaps it might be possible to make the function conditional on it taking place on the 'client' post type, so that when you are editing the 'equipment' no post id is set to the relationship? I hope that is a clear enough description.

    Thanks in advance to any help or guidance you can provide.

    <div>
    //Add a connection to the post itself after submitting the post
    add_action( 'rwmb_frontend_after_process',
           function( $config, $post_id ) 
           {
    MB_Relationships_API::add( get_queried_object_id(), $post_id, 'clients-and-equipment', $order_from = 1, $order_to = 1 );
    }, 10, 2 );
    </div>
Viewing 16 post (of 16 total)