Skip Navigation

[Resolved] How to change number of default options/iteems loaded with select2

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to change number of default options/iteems loaded with select2

Solution:

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/filtering-the-search-list-in-a-relationship-form/page/2/#post-1115021

Relevant Documentation:

This support ticket is created 5 years, 8 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 18 replies, has 2 voices.

Last updated by grahamA 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1109452
cred_list.jpg

Hi. I have a relationship form (see attached image) and have 2 issues.
1. The search list displayed is only showing a restricted number of eligible posts. There does not appear to be any settings to control this.

2.How can I restrict the posts appearing in the search list to posts created by the author only.

Both these attributes are easily managed in the views creation process but I cannot find a way to do them in a relationship form. Please can you advise me?

Many thanks

Graham

#1110534

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.
1. The search list displayed is only showing a restricted number of eligible posts. There does not appear to be any settings to control this.
==> I would like to have more information on this, can you share test case example so that I can understand what exactly you are looking for.

2.How can I restrict the posts appearing in the search list to posts created by the author only.
==> Well - could you please tell me which filter you are using and where?

#1110599
cred_list_2.jpg

Hi Minesh

I will try to explain, unfortunately I am unable to give you access to the site due to the sensitive content.

I have the solution for the other question no.2 🙂 I had missed the filters in 'Form content'

1. Problem remains - see more detail here.
I have a post type "clients" and a post "freds clients" - type 'clients'
I have a post type "presentation list" and a post "freds playlist"
I have a relationship many to many for 'clients-playlist'
I have a post type 'project' and 30 'project' posts
I am using a relationship form to allow the user to assign 'project' posts to 'freds playlist' as in my previous picture.
I wish to see all 30 unassigned potential posts in the search list to allow me to apply the relationship, but I am only seeing 10 but I know there are more available because I see others if I change the sort order.
Please see new attached image.

#1111498

Minesh
Supporter

Languages: English (English )

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

Ahh - Do you mean that it should display all posts by default with the field? If Yes - the field is rendered using select2, so by default there will be 10-15 post should be displayed but you can use the input box available where you should search for your post.

#1111589

This is not a good solution as it requires a user to know every title of every post in their list.

You have a max_results argument for this short code. How can I change it to use this please?

Thxs

#1112224

Minesh
Supporter

Languages: English (English )

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

Yes - I agree with you. Currently, there is no filter available to override the limit argument.

But I think your request is valid and I will take your request as a new feature request and report to our Devs. If our Devs agree, they will implement it and it will be available in near future release.

I will update you here with progress.

#1112367

Hi Minesh

This feels more like a bug than a feature issue. The ability is critical to our UX.
I see here that select2 does deliver the full list. hidden link also the ability to add multiples.

May I request your developers can point us to the relevant code files in your plugin where we can address this (we have some experienced developers here but a point in the right direction would speed things up.

Thanks

#1112721

Minesh
Supporter

Languages: English (English )

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

The file from the select2 rendered is located at following path:

cred-frontend-editor\vendor\toolset\toolset-common\inc\autoloaded\ajax_handler\select2_suggest_posts_by_post_type.php

Where you will find the code - at line #88:

$results = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT ID, post_type, post_title, post_name 
				FROM {$wpdb->posts} 
				WHERE {$search_query} 
				AND post_status = 'publish' 
				{$post_type_query} 
				{$author_query} 
				ORDER BY %s %s
				LIMIT 0, 15",
				$values_to_prepare
			)
		);

However, I already ask Devs to share filter to override the limit.

#1112813

Minesh
Supporter

Languages: English (English )

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

We file the feature request and made available for voting to all users.

Feel free to share your vote:
=> https://toolset.com/feature-request/?wpv_post_search=select&wpv_view_count=686737&wpv-wpcf-plugins=CRED

#1112979

Thanks for the information.

The development team would only give me an hour but they have said that for some reason this code is not actually called. They can even rename the file without any negative effect.

So I am still reliant on your guys fixing it. If it can be shown as a bug rather than a feature request can it be escalated?

#1112988

Minesh
Supporter

Languages: English (English )

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

ahh - unfortunately - I copy the wrong file name.

I've tested again and the full file path is:

plugins\cred-frontend-editor\vendor\toolset\toolset-common\inc\autoloaded\ajax_handler\select2_suggest_posts_by_post_type.php

At line #63 you will find following code:

$results = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT ID, post_type, post_title, post_name 
				FROM {$wpdb->posts} 
				WHERE post_status = 'publish' 
				{$post_type_query} 
				{$author_query} 
				ORDER BY %s %s
				LIMIT 0, 15",
				$values_to_prepare
			)
		)

you can change the limit and check.

#1113028

Minesh
Supporter

Languages: English (English )

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

As you can see with the following screenshot:
=> hidden link

I've changed the number of posts to display to 5 with relationship form field and its working.

Please do the hard refresh (delete browser cache) once you change the limit and check.

#1113029

strange, it is the same path that you sent originally.

They also tried the select2_suggest_posts_by_title.php file too.

The problem/bug remains therefore can you escalate it please.

#1113030

Minesh
Supporter

Languages: English (English )

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

Yes - the same path but line number is different: At line #63 you will find code:

Well - are you using a post-relationship filter or post-relationship forms?

Can you share problem URL and access so I can check and fix it for you.

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

#1114966

Minesh
Supporter

Languages: English (English )

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

Well - I just received access details today.

Could you please share problem URL where I can see the form or where you want to apply the change?

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

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