Jump to content

double sort order issue


davo
 Share

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


}

 

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

Link to comment
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");
Link to comment
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.

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...