Jump to content

pages selector empty and unique field values


bbb
 Share

Recommended Posts

I'm trying to figure out how to create a selector that will find pages where a certain text field is either empty of unique. I have about 3500 records where the majority of have a specific field which is simply empty, there some records however that will have a certain value filled in this same field and some of these values are the same. I want to only select the first page which is found with this value and exclude the rest of these pages with the same value.

Any ideas?

Link to comment
Share on other sites

 

7 minutes ago, Barry said:

empty of unique

Was this meant to read empty or unique? You want to select all records whose a certain text field is empty or has unique values?

There isn't a selector option to filter pages by unique value, but you can do something like this

<?php namespace ProcessWire;

$empties = $pages->findMany("template=record, textField=''");
$fulls = $pages->findMany("template=record, textField!=''");
$uniques = new PageArray();
$fieldValues = [];
foreach ($fulls as $record) {
    if (in_array($record->textField, $fieldValues)) continue;
    $uniques->add($record);
}

$uniqueOrEmpty = $empties->import($uniques);

 

  • Thanks 1
Link to comment
Share on other sites

I edited this code a little and it worked perfectly! Thanks

<?php namespace ProcessWire;

$empties = $pages->findMany("template=record, textField=''");
$fulls = $pages->findMany("template=record, textField!=''");
$uniques = new PageArray();
$fieldValues = [];
foreach ($fulls as $record) {
    if (in_array($record->textField, $fieldValues)) continue;
    $uniques->add($record);
}

$uniqueOrEmpty = $empties->import($uniques);
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...