Jump to content

Admin Ajax search: search by page id number


lpa
 Share

Recommended Posts

I tried to add the page id to be searchable in the admin Ajax search-field. The help message says the field has to be text-based: "Enter the names for one or more text-based fields that you want to search, separating each by a space." Is there any way to add the page id to be searchable?

Link to comment
Share on other sites

  • 1 year later...

beauty! Works perfectly well - thanks!

I got stuck in the forum search, looking for admin live search and integer values.

I cite here the code, just in case:

On 5/7/2020 at 11:56 PM, Robin S said:

 


$wire->addHookAfter('ProcessPageSearch::findReady', function(HookEvent $event) {
	$selector = $event->return;
	$q = $event->wire('input')->get('q');
	// If the admin search query is a number
	if(is_numeric($q)) {
		// Get the individual pieces of the selector
		$selector_pieces = explode(', ', $selector);
		// Modify the first piece so that it includes an ID clause in an OR-group
		$selector_pieces[0] = "({$selector_pieces[0]}), (id=$q)";
		// Replace the original selector
		$event->return = implode(', ', $selector_pieces);
	}
});

2020-05-08_095548.png.946178db80b95a8a1483960c250250ba.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...