Jump to content
davo

double sort order issue

Recommended Posts

I've been using a function for some time now which sorts an array by the title of a linked page 'DMC_country_represented' title but then should reorder it by the parent page title to group the pages together.

 

Recently the order is no longer working and a couple of the list items are out of alphabetical order. The only thing i'm aware of recently that has changed is a core upgrade to 2.7.2.

 

Any advice welcome please.

 

function dmc_list($names){
    
    $dmcs = wire('pages')->find("template=dmc, DMC_represented=1, sort=DMC_country_represented");
    $dmcs->sort("parent.title");
    $total = $dmcs->count();
    $items_per_column =  ceil($total / 3);
    $count = 0;    

echo"<div class='row'>";
    echo "<div class='col-md-4'>"; //start the first column
        echo '<ul>'; // start your first list
        foreach($dmcs as $dmc){
            
            $region = $dmc->parent->title;
	    $regionid = $dmc->parent->id;	
            if($region !== $new_region) echo "<li class='list-group-item list-group-item-info'><b>{$region} {$regionid} </b></li>";
						if($names=="names") { 
									$showname = " - " . $dmc->title;
									}
					$link = "<a href='$dmc->url'>{$dmc->DMC_country_represented->title} {$dmc->sub_country->title} $showname {$regionid} {$count} of {$items_per_column} in total {$total}</a>";
                                        echo "<li>{$link} </li>";
                        
                    if(++$count%$items_per_column) { // this will be false when we are on the last item in column
                        echo "";
                    } else { // this part will run when we are on the last item in the column
                        echo "</ul></div>";
                        if($count !== $total) echo "<div class='col-md-4'><ul>"; // this will start a new column unless we're on the last item.
			
                    }
			$new_region = $dmc->parent->title; // why the same variable?
                                                        
                } // end foreach                                                                                
echo "</div>"; // end row


}

 

Share this post


Link to post
Share on other sites

This is reminding me of this post: 

Try adding the sort to your selector. Not sure if we have a weird bug going on here. Would be good to know what version of PW @bmacnaughton is running and also if you have the same problem on 2.7.3, or 2.8.x or 3.x

 

Share this post


Link to post
Share on other sites

Thanks Adrian,

Are there any issues with upgrading to 2.8? I couldn't easily find what the name space issue is.

 

How do you mean adding the sort to the selector? I already have one sort there and can't seem to add parent.title

Share this post


Link to post
Share on other sites
3 minutes ago, davo said:

Are there any issues with upgrading to 2.8? I couldn't easily find what the name space issue is.

There are no namespaces in 2.8 - otherwise it is identical to 3.x. 2.8 is designed as an ideal upgrade for already live 2.x sites.

 

4 minutes ago, davo said:

How do you mean adding the sort to the selector? I already have one sort there and can't seem to add parent.title

$dmcs = wire('pages')->find("template=dmc, DMC_represented=1, sort=DMC_country_represented, sort=parent.title");

Share this post


Link to post
Share on other sites

That's what I tried.

 

But i get this complaint back when viewing the page:

Error: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_sort_parent_title.title' in 'order clause' (in /var/www/vhosts/dudmc.com/httpdocs/wire/core/PageFinder.php line 298)#0 [internal function]: PageFinder->___find(Object(Selectors), Array)#1 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(398): call_user_func_array(Array, Array)#2 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(333): Wire->runHooks('find', Array)#3 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Pages.php(216): Wire->__call('find', Array)#4 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Pages.php(216): PageFinder->find(Object(Selectors), Array)#5 [internal function]: Pages->___find('template=dmc, D...')#6 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(398): call_user_func_array(Array, Array)#7 /var/www/vhosts/dudmc.com/httpdocs/wire/core/Wire.php(333): Wire->runHooks('find', Array)#8 /var/www/vhosts/dudmc.com/httpdocs/site/templates/myfunctionlib.inc(35): Wire->__call('find', Array)#9 /var/www/vhosts/dud

 


This error message was shown because you are logged in as a Superuser. Error has been logged.

Share this post


Link to post
Share on other sites

Adrian,

I think the upgrade to 2.8 may have sorted it. I'll keep testing tomorrow but first impressions looks good.

ta

 

  • Like 2

Share this post


Link to post
Share on other sites

After a week of testing in 2.8 this appears resolved. I suspect a bug in 2.7 .3

 

thanks for the help 

  • Like 1

Share this post


Link to post
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

  • 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 louisstephens
      I have done a bit of searching, but I can not seem to find an actual answer. I have a list of services as child pages under "Services". I can output the services just fine, but I cant wrap my head around how to group them "alphabetically" like:
      Services A - Service "A" 1 - Service "A" 2 - Service "A" 3 B - Service "B" 1 - Service "B" 2 - Service "B" 3 C - Service "C" 1 - Service "C" 2 - Service "C" 3 Has anyone achieved this type of functionality before?
    • By nickngqs
      How do you guys sort according to the order of page listing?

      My template is sort order none, so I assume it would return according to order of page listing.
    • By rolisx
      Hi all!
      I have a little problem here. I want to sort a list of addresses by streetname and then by number. First, I just had a field "prod_objekt" (address) containing both and then have a foreach loop like this: $pages->get('/produzenten/')->prod_repeater->sort('prod_objekt') as $produzent. Unfortunately, this would not sort by streetnumber if I had the same streetname but multiple numbers.
      Now, I thought I could sort by two fields. prod_object (adress) first and then by prod_hausnummer (streetnumber). But I just don't know the code for it. I tried this: $pages->get('/produzenten/')->prod_repeater->sort('prod_objekt.prod_hausnummer') as $produzent, but it wouldn't work.
      Any ideas on how to solve this?
      Thanks for your help
      Roli
    • By celfred
      Hello,
      I'm facing an issue with my page fieldtype. Pages appear in the order they were created although I'd like to see them sorted in alphabetical order (by title). The pages are well-sorted in my tree, but in that particular Page fieldtype (on another page), I can't find any place where I would decide on what field I can sort them. Am I missing something here ?
      Let me know if I'm not clear enough in my explanations.
      Thanks in advance for a clue  
×
×
  • Create New...