Registering a user with a relationship field

Support MB User Profile Registering a user with a relationship field

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #41013
    YasmineYasmine
    Participant

    Hi Peter,

    I promise this is the last from me!

    I have a frontend form to register a new user, in it I have added a relationship field to attach the user to a post (in my case, a university)

    However, this form is creating a new meta box and not using the relationship field that I created. This is my code to add the relationship field to the user register form:

    [
                    'name'       => __( 'University', 'your-text-domain' ),
                    'id'         => 'university_user',
                    'type'       => 'post',
                    'post_type'  => ['university'],
                    'field_type' => 'select_advanced',
    					   'field' => [
                'query_args' => [		  		  
    				 'orderby' => 'title',
    			 'order' => 'ASC',
                ],],],
    

    Can you see where I am going wrong?

    Yasmine

    #41014
    YasmineYasmine
    Participant

    university_user is the name of the relationship ID

    #41025
    PeterPeter
    Moderator

    Hello,

    It's not possible to add the relationship ID as a field ID like that. If you want to display the relationship meta box on the frontend, please add this meta box ID to the frontend shortcode university_user_relationships_from or university_user_relationships_to

    For example: [mb_frontend_form id="meta-box-id1,university_user_relationships_to"]

    Please read more on this topic https://support.metabox.io/topic/mb-relationships-mb-frontend-submission/?swcfpc=1#post-16736

    #41034
    YasmineYasmine
    Participant

    Hi Peter,

    Ok so that means I made it :

    [mb_frontend_form id="mb_user_profile_register,university_user_relationships_to"  label_submit="Add new" confirmation="Your academic has been added" role="contributor" show_if_user_can="create_users" email_as_username='true' email_confirmation="false" password_strength="false" ]

    But with this, all I get is a select already created user box. Whereas...

    [mb_user_profile_register label_submit="Add new" confirmation="Your academic has been added" role="contributor" show_if_user_can="create_users" email_as_username='true' email_confirmation="false" password_strength="false" ]

    Rendered the correct form and with all my added fields, which I added via a php snippet. Only the relationship not working.

    I removed the relationship field (that I shared in my last code) from the php snippet

    And I also tried _relationship_from - but in that case, nothing rendered.

    What am I now doing wrong?

    Many thanks,
    Yasmine

    #41035
    PeterPeter
    Moderator

    Hello,

    Can you please share some screenshots of the issue on your site and the relationship ID? Also, please note that: mb_user_profile_register is not a field group (meta box) ID to add to the frontend submission shortcode. It's the shortcode name of the user profile.
    Did you create a field group with the ID mb_user_profile_register?

    #41040
    YasmineYasmine
    Participant

    Oh but I want to add the relationship field into the profile register. As it is a university, I want to attach the university via a relationship post when we register a new user..

    So in the first message, the code I shared was to add to edit this:

    function add_more_registration_fields($fields) {
            $first_fields = [ ...	
                [
    #41041
    YasmineYasmine
    Participant

    And when I add it in the correct way that you suggest:

    '[mb_user_profile_register mb_frontend_form id="university_user_relationships_to"  label_submit="Add new" confirmation="Your academic has been added" role="contributor" show_if_user_can="create_users" email_as_username='true' email_confirmation="false" password_strength="false" ]'

    At the bottom, it does not link to selecting the university post. It just lets you select a different user - not university.

    I am unable to use pastebin to share a screenshot.

    #41042
    YasmineYasmine
    Participant

    Oh I see - it needed to be 'from'. Sorry about that.

    The only issue now is that is right at the bottom of the form in a position that does not make sense and does not have a title - so does not match how I formatted the rest of the form. How can I fix this?

    Thank you.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.