Jump to content

Merge selectors


valan
 Share

Recommended Posts

@AndZyk thanks.

Yes, there are associative and regular arrays used for selectors. It is exactly a reason of the question - how to merge them and get one:

$selector1 = 'template=basic-page|product';
$selector2 = [
  'title|body%=' => $sanitizer->text($input->get('q')),
];
$selector3 = [
  ['categories', '=', $input->get('categories'), 'int'],
  ['sort', '-created']
]

$selector = mergeSelectors($selector1, $selector2, $selector3); // <- I need this kind of method
$results = $pages->find($selector);

 

Link to comment
Share on other sites

Hi @valan, you need something like this?

$selector1 = "template=basic-page";
$selector2 = "status=123";

$mergedSelectors = $this->wire(new Selectors($selector1));
$mergedSelectors->add($this->wire(new Selectors($selector2))); // Updated see comment valan

// to output a PageArray

echo $this->wire('pages')->find($mergedSelectors);

// or to output the selector as string

echo $mergedSelectors->__toString();

// See: /wire/core/Selectors.php

 

Edited by arjen
fixed a code error
  • Like 5
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

×
×
  • Create New...