Jump to content

Keeping order of page IDs in pagearray


alexcapes
 Share

Recommended Posts

Hi,

I have an array of Page IDs ($matches) which I'm using in a PageArray ($matches_limit):

$matches_limit = $pages->find("id=$matches, limit=$page_limit");

This is working fine but I need to maintain the sort order of $matches, however $matches_limit reorders the $matches (I guess to sort=sort).

Is it possible somehow to maintain the order $matches when outputted in the pagearray?

 

 

 

Link to comment
Share on other sites

4 minutes ago, LostKobrakai said:

$matches->slice(0, $limit);

 

 

Thanks LostKobrakai, that works!

However I do need to paginate the results and using slice() breaks the Processwire pagination.

Any ideas on how pagination can work with a solution?

 

 

 

 

Link to comment
Share on other sites

Amazing!

I got there with some minor updates to LostKobrakai's code...

	$start_val = (($input->pageNum * $limit) - $limit);

        $matches->setStart($start_val);
        $matches->setTotal($matches->count);
        $matches->setLimit($limit);

        $matches_limit = $matches->slice($start_val, $limit);

Created a variable $start_val for the start value and updated the sum to -$limit value.

I created a variable called $matches_limit for displaying the search results, as I can't put slice() into the pagination renderPager().

The slice() uses the $start_val to correctly get the pages for each paginated results page too.

Thanks as always LostKobrakai.

 

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.
  • Similar Content

    • By opalepatrick
      Hi, trying to order pages by modified date, date. I can do 'sort=-date_modified, sort=-date' but that will always put the modified date first regardless of actual date order. I just want to coalesce the two fields and sort. Any ideas would be appreciated.
    • By ngrmm
      i have a event-page with a table.
      first column in this table is page-reference-field
      how can i find out if a urlSegment matches one of the rows having the same page-reference-field (page-id)?
      // all guests $allguests = new pageArray(); foreach($page->event_guests_table as $event_guests_table_row) { $allguests->prepend($event_table_row->guest); } // echo allguests would output: 1101|1102|1103|… // domain.tld/event/1101/ // show content if guest is in the table or redirect if($input->urlSegment1 ~= $allguests ) { // show content } else { // redirect }  
      which selector operator do i have to use? the one above does not work
    • By Noel Boss
      Hi everyone 🙌
      Is there a way to order the language tabs in the backend? Currently, they seem to be ordered based on the created date (or id?) …
      ( time passes … ⏰ 🚶‍♂️)
      Just answered my own question. One can reorder the languages in the page tree under admin » languages or directly in the DB » pages » template_id=54 » sord field.
      Anyone knows if there are side effects when moving the default language from sort 0 to somewhere higher?
    • By Peter Knight
      <?php $Cats=$pages->find("parent=1086, id!=$page, sort=sort"); foreach($Cats as $Cat) { echo " I have a selector that pulls in 4 child pages of a parent and the order is set to reflect the order of the tree.
      My client has asked that instead of
      Cat 1 | Cat 2 | Cat 3 | Cat 4
      we instead display
      Cat 4 | Cat 1 | Cat 2 | Cat 3 
      However, I can't change the sort order in the tree.
      Can anyone guide me on the correct approach here?
      Thanks
       
    • By Sanyaissues
      Hi, I have a page with a repeater called teams with two fields: team (a pageReference with a list of teams) and people (a pageReference with a list of people who likes this team).
      I'm trying to populate the people field in the repeater according to the value of the team field in the same repeater. So far. I'm able to get the pageArray that I want to assign to the people field, but i don't know how to "save" the value for each instance of the repeater.
      I hope somebody can give me a light. Thanks in advance.
       
      $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'people') { $repeaterField = $event->arguments('page')->teams; foreach ($repeaterField as $t) { // Is this the way to loop the instances of the repeater? $team = $t->team->id; $t->people = $event->pages->find("template=user, team={$team}"); var_dump($t->people); // This returns the values that i want to assign for each repeate instance $event->return = $t->people; // I hope this assign a custom pageArray for each repeater, but it assigns the same for all the instances of the repeater } } });  
×
×
  • Create New...