Recommended Posts

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

Share this post


Link to post
Share on other sites

Thanks @Zeka

But I don't know where to put that code to make it work..

<?php
  foreach ($pages->get('/produzenten/')->prod_repeater->sort('prod_objekt') as $produzent) { 
?>
<div><a><?= $produzent->prod_objekt ?> <?= $produzent->prod_hausnummer ?>, <?= $produzent->prod_ort ?></a></div>
<?php
  }
?>

The above will only sort by prod_objekt (streetname)...

Share this post


Link to post
Share on other sites
2 hours ago, rolisx said:

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.

Use a comma (and perhaps a white space) between your sort properties.

$pages->get('/produzenten/')->prod_repeater->sort('prod_objekt, prod_hausnummer') as $produzent

 

  • Like 2

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 Kevin C. McCarthy
      I am desperate to learn how to you ProcessWire to it's fullest potential, and while the documentation is great and always appreciated, I simply can't follow along because it gets way too technical without really showing how applicable and versatile it can be. Then again, I'm almost a moderate understanding of PHP and no experience with APIs or programming JavaScript—so it's probably leagues ahead of where I am at the moment. That said, I learn best by watching and the doing. Think Codecademy or FreeCodeCamp. I was wonder if there are any video tutorials or walk-through lessons to give me a greater understanding of ProcessWire and how to utilize it effectively.
      For some background, I'm great with WordPress and I'm great with writing websites by hand with Notepad only. The biggest hurdles I have with PW is the phrasing is so far left of WP at times that it's a massive hurdle for me to get over. Like in WP, themes, templates, etc are totally different things. And as someone who builds WP sites for a living, it gets hard to kill those old preconceived meanings.
      I want to start building out PW sites for numerous reasons. For one, most of my clients they would benefit from it vs the Bloated Beast. Two, it would allow me to differentiate me in a market saturated by WP devs. I know I have a long ways to go until I reach that point of considering myself a "PW dev", but I am desperate for resources to help me wrap my head around it.
      I've built my own website in PW but TBH it only handles some of the data while most of the text has been hard-coded into the PHP template files because I couldn't get my my head around the "best practice" of structuring the data.
      Anyway, enough rambling, I'm just hoping those of you in the community can point me to easily-digestible sources out there that can help move me along so I can actually benefit from using the platform. Thank you!
    • By Guy Incognito
      I'm trying to make an AJAX call from within a template to a php script within my templates folder, but I'm getting a 404 from all URLs. Is there a proper way to directly address scripts within PW templates? I've read it will work in the site root, but I'd rather keep all the code together if possible.
    • By Eunico Cornelius
      Hi, I am trying to create a PHP page in my website that is hidden and produce a plain JSON format. However, when I implement json_encode on my string, the result is not only a plain JSON but also a <!DOCTYPE HTML>.... I have created a new page and a new template that has it's cache disabled, but it still doesn't work.
      this is what my code looks like 
      <?PHP $useMain=false; $data = "[{'title':'AAAAA','url':'https://google.com'}]"; header('Content-Type: application/json'); echo json_encode($data); ?> This is what I currently get
      "[{'title':'AAAAA','url':'https:\/\/google.com'}]"<!DOCTYPE html><html>....</html> This is what I am trying to achieve
      "[{'title':'AAAAA','url':'https:\/\/google.com'}]" What am I missing here? I am also using ProCache.(dont know if it has any influence since I created and disable cache in a new template)
    • By neophron
      Hi,
      I want to show only on the start page a div with some content.
      I'm trying with my rudimentary php skills to construct this:
      <?php if($page->isHomePage()): ?> <div class="xx"> lorem ipsum </div> <?php else: ?> <?php endif ?>  
      Ok, I know that isHomePage will give me an error. But, is there a methods how to detect the start page and then to echo a div?
      I thought about
      <?php if($page->is($home)): ?> where »home« is the template and the start page is connected with it. I'm using the older templating method. 
      What would you recommend?
      Thank you 
    • By bystefu
      Hello,i  am new here. A hour ago i bought a vps and i want  to make a website about movies.
      - a home page
      - a movie page with title, description,  trailer ,year and actors
      -categories, tags 
      - a complex search page by name,tags,year and acts
      - posts, latest news (about site)
       
      It's already to much
      I leave wordpress,from my needs it's very complicated. So,minimal speaking, i can do that with this cms,and which is the steps? I don't know yet how this work.Thank you,and sorry for my eng.