Skip Navigation

[Résolu] CRED: more than 10 matches to _wpcf_belongs_member_id field

This support ticket is created Il y a 2 années et 7 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 réponses, has 3 voix.

Last updated by Shane Il y a 2 années et 7 mois.

Assisted by: Shane.

Auteur
Publications
#2145931

hidden link

This is a Chamber of Commerce website.

The CRED form has been in use for about 4 years but the Chamber administrator experienced this issue for the first time today.

The Company Name field is:
[cred_field field='_wpcf_belongs_member_id' value='']

If you type in the box with your company name, it finds up to 10 matches. My problem is, there are more than 10 companies in the database that use the word "Batesville" (the name of the city). Is there a way to have this field display all matches, or can I change the default to more than 10?

The specific use case is that there is a business whose name IS "Batesville". No second word. And their listing ("Batesville") isn't one of the 10 results. There is literally no way to select their name/post. How might I be able to make it available to be chosen?

#2146087

Hello, there are a couple of shortcode attribute options you can try to resolve this.
1. Try adding max_results, and set a larger value like 20:

[cred_field field='_wpcf_belongs_member_id' value='' max_results='20']

2. It looks like the default sort right now is based on post ID, which is pretty useless. Try adding order, set to be based on the post title:

[cred_field field='_wpcf_belongs_member_id' value='' order='title']

You could try one or both of these options. Let me know if these options are ineffective, and we can look for alternatives.

#2146121

Christian, thank you. Unfortunately neither of these works, and now I'm wondering if there's another issue.

I applied max_results='20' and also order='title' and nothing changed.

I am correctly passing through attributes to the shortcode. When I view source on the page I can see the "class", "data-orderby" and "data-order" that I'm putting in the shortcode. But no matter what I put in the shortcode for "order" and "max_results", the output does not change.

I also tried putting in a "placeholder" for testing's sake and that does NOT appear on the form.

One thing I am noticing which may or may not be helpful. You wanted me to declare order='title'. However, if I click "Add Fields" in the Form Editor, select "member Parent" and then choose the radio button for Title for the Order, the shortcode does not show order='title'. It seems like title is the default. Yet the site isn't honoring that, whether by default or when explicitly declared.

If you have an alternative to suggest, please do. Or maybe there's a conflict on my side...if you could help me troubleshoot that, if needed, I'd appreciate it. Thank you!

#2146927

Okay I see...let's take a closer look. The _wpcf_belongs_{parent-post-type-slug}_id syntax for defining the parent post in a one-to-many (O2M) post relationship is an indication this Form (and this site) was probably created before the new post relationships system was released. The new system no longer relies on custom field values, but implements proprietary database tables specific to relationships features. The fact that this is a legacy post relationship may mean some of the features in this field are unavailable, but I'm not sure offhand. The documentation I have available is not comprehensive enough to give me those details, and I would need to get some feedback from the team to give you the best answer here. Can you tell me more about the site?
- Add your site's debug information as described in our FAQ post here: https://toolset.com/faq/provide-debug-information-faster-support/ This will help me determine which Toolset plugins you have installed and the versions of each plugin, the other 3rd-party plugins on your site, and some relevant system/environment details.
- When logged in to wp-admin as an Administrator, please go to wp-admin > Toolset > Relationships if that main menu link exists, and let me know what you see on that page.

I'll review everything and try to get some feedback about the features available for the select2.js field in legacy post relationship fields

#2146955

Christian, thank you.

Debug info included.

For Relationships, I have not enabled them. The message on the page:

Your site has relationships that use the old storage.
A "post relationship" is the connection between different posts on a website. This particularly includes "custom post types".

There are three possible types of post relationships:

One-to-many
Many-to-many
One-to-one
Using a post relationship makes it easier to build and run advanced sites.

Building a site using related posts allows you to separate information into independent pieces, which can then be combined in multiple ways. This eliminates data duplication, enabling you to edit each piece of information only once and use it in any manner you desire.

This is important for both large and small sites.

Please read our comprehensive guide to learn how to use Toolset to leverage the power behind post relationships.

If you do not need to develop or extend this site with new the relationship functionality, it is perfectly safe to not run the migration.

I won't rule out an issue on my end. This site went through a number of twists and turns while it was under development as the client changed their mind about stuff on numerous occasions. Also it was launched during the period of time when Toolset was actively encouraging usage of Layouts. So I do have some things in place which might not be standard and may be contributing to this issue.

#2150693

Christian, I thought I'd check in just to see if there was anything useful in my debug information, or if you have any other ideas on how I can accomplish my goal.

I recognize the original issue may be an edge case, where the search term is common and there isn't any other word to make it unique. But I would like to figure out why these shortcode attributes aren't being honored. Thank you for your help.

#2152871

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Christian is currently on vacation at the moment so I will be doing the follow up here for him.

Based on what i've read so far you are using the old relationship model which may be a factor in why you're only getting 10 results.

Additionally what I would first try to do after ensuring that i've made a full backup is to migrate to the new relationship model.

When you go to Toolset -> Relationships are you able to see any button that would allow you to migrate to the new relationship model ?

Thanks,
Shane

#2153791

Shane, thank you.

I created a staging site to work with rather than editing on the live site.

After migrating to the new relationship model, and replacing the original [cred_field] shortcode with a new one that uses the new relationships, I had partial success. But it still should be good enough to accomplish my specific need.

[cred_field field='@member_job.parent' class='form-control' output='bootstrap' select_text='--- not set ---' order='title' ordering='asc']

With this shortcode, I had to explicitly declare order=title and ordering=asc even though I kept those default options when creating the shortcode. When the shortcode was inserted those attributes weren't present since they're the default, but I had to add them in. However, when I did add them in, they did work.

The max_results=20 that Christian suggested earlier still didn't work.

However, as long as I am able to have order=title and ordering=asc applied properly, that solves my specific issue. The member whose full name is one single word, now shows up first in the listing. For all the others beyond the 10th result on that first word, they can continue typing. After typing the first letter of the second word in their name, there should be fewer than 10 matches at that point.

I would like to leave this ticket open temporarily, as I have not yet performed the update on the live website. I will do that over the weekend during a period of lesser traffic, and when the client/administrator is not actively using the site. As soon as the adjustments are made on the live site and they are satisfactory I will then close the ticket.

Thank you for your help.

#2154081

I just applied the change on the live site and it looks like it's going to work.

One more question that I didn't think to ask before now. Is there a way to require that a Company Name field be selected from the dropdown? If I leave that field blank it doesn't generate "this field is required" like the other fields on the form.

Thank you again for your help.

#2155409

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I'm happy that we could've come to a suitable solution for this one.

In this case you should be able to use the hook below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This should allow you to write a custom validation for the field so that the form doesn't submit without the field being selected.

Thanks,
Shane

#2155451

Shane, thank you.

What would the name of the field be, for use in the validation function?

I had something previously that used '_wpcf_belongs_member_id'. What should it be, now that I'm using the new relationships?

if ( empty($fields['_wpcf_belongs_member_id']['value']) ) {
$errors['_wpcf_belongs_member_id']='Company Name is required';
}

#2155535

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

It should be "@{relationship_slug}_parent" I believe this is what is being passed in the payload for the form.

Replace the relationship_slug with the actual slug. If "@{relationship_slug}_parent" doesn't work try "@{relationship_slug}-parent"

Please let me know if this helps.
Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.