I'm setting up a form with a relationship between two post types. It's a contact form and I want to include a field to show all countries in a dropdown, so that users inform me which countries are they from. I've created a CPT for countries and connected with another CPT I've created for Contacts. I'm now developing the form and included the "Countries-Contacts" relationship field. The problem is that in front-end the dropdown only shows 10 countries (and not in alphabetic order). How can I have a dropdown to show all 211 countries I have?
I've checked support ticket "https://toolset.com/forums/topic/post-relationship-field-with-use_select2always-only-has-ten-results/#post-1240194" but since I have no experience with codingit was of no help to me... I don't really know where to include the coding suggested in the ticket.
Thank you in advance.
Hello,
You can put that custom codes into your theme file "functions.php", for example:
add_filter('cred_select2_ajax_get_potential_relationship_parents_query_limit', function($limit){
return 200;
});
For the "alphabetic order" problem, please edit the post form you mentioned above, find and edit the relationship field, make sure you are using option "Order options by title" "Ascending", see my screenshot orderby.JPG
Hello Luo,
I'm sorry but I have no coding experience. Where exactly should I put the custom code you're suggesting? Where can I find the theme file "functions.php"? Is it in the Form Editor - expert mode? Could you please send me a screenshot for this? Thank you.
Please provide a test site with the same problem, also point out the problem page URLs, I can setup a demo for you
Thanks for the details, I have done below modifications in your website:
1) Edit the post form "Info Request":
hidden link
In form content area, switch to expert mode, change the relationship field shortcode to:
[cred_field field='@country-contact.parent' class='form-control' output='bootstrap' select_text='--- not set ---' order='title' ordering='asc']
More help:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_form
2) Edit theme file "functions.php":
hidden link
line 34~36, add below lines:
add_filter('cred_select2_ajax_get_potential_relationship_parents_query_limit', function($limit){
return 300;
});
Please check if it is fixed, thanks
Hello Luo, it's fixed. Many thanks for your support!
Feel free to create new ticket for other new questions