Skip Navigation

[Closed] Check that a value is unique based on child/parent relationship

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1780969

Tell us what you are trying to do?
I'm trying to make sure that usernames are unique to the parent 'Client' only. So that different clients can have users with the same username.

This is what I have and it does work in looking up the username, the issue is that it doesn't limit to the parent 'Client' that the account is assigned too.

 $the_id = '76854';
        $args = array(
                    'meta_query' => array(
						'post_type' => 'wirelessaccount',
						'posts_per_page' => -1,
						'relation' => 'AND',
                        array('key' => 'wpcf-wireless-account-username',
							  'value' => $username_sanitized,
							  'compare' => '='
                            ),
						'toolset_relationships' => array(
							'role' => 'child',
							'related_to' => $the_id,
							'relationship' => 'client-wireless-account'
							 )),
                    );
		 
		$bposts = get_posts($args);
		
        //check if username value is already in the database.
        if (count($bposts) > 0){
            $errors['wpcf-wireless-account-username'] = 'Username already exists. Please select a different username.';
        }

What is the link to your site?

#1781263

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I'm trying to make sure that usernames are unique to the parent 'Client' only. So that different clients can have users with the same username.
==>
I will require little bit more information about your current setup and post-relationship information.
- Between what post types you are post-relationship and what is the post-relaitonship type (one-to-many)?

I see you must have added the code you shared within the Toolset form's hook: "cred_form_validate"
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
The form to which you added the "cred_form_validate" is your child post form?

This is what I have and it does work in looking up the username, the issue is that it doesn't limit to the parent 'Client' that the account is assigned too.
==>
I see you query the post type "wirelessaccount" within your code. Can you please share with test case example what username should be allowed and what username should not be allowed to what post that at what action.

In addition to that, if you can share problem URL and access details that would help me to guide you in the right direciton.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1784323

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

When you say:
You just can't have duplicate username assigned to the same client.
==>
I see you have one-to-many relationship between post type "Clients" and "Wireless Accounts".
- Wireless Account posttype have the custom field "username" - do you want to target that custom field or the "Wireless Account" post title should be unique per client?

Also, Can you please share the link where you added the form?
And where you added the custom code you shared to the "wirelessaccount-functions.php" snipped you added to "Custom Code" section offered by Toolset?

#1784377

I am checking against the username custom field. The current query works except for it checks against all clients and not just the parent of the current wireless account being entered.

I'm away from my computer so I can't login to stage and get you an exact link. I will later.

#1785695

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ye - please send me the problem URL where I can see the form you added.

The topic ‘[Closed] Check that a value is unique based on child/parent relationship’ is closed to new replies.