Jump to content

selector best way to use


a.masca
 Share

Recommended Posts

Hello,

sorry but I have a problem that really can't solve by myself and I'm obliged to ask you.

In my project I have this type of pages:

- client (cliente in italian)

- supplier (fornitore in italian)

- project (progetto in italian)

Only in every project I have all the link with client (pagefield single) and suppliers (pagefield multiple).

Now the question:

which is the quickest way to find all the suppliers for a specific client, and also how many projects every supplier have done for this specific client?

I solved already but with a lot of foreach .... I'm sure that with selector there must be a quick way.

this is my code:

foreach ($pages->findmany("template=fornitore") as $fornitore) {
   $progetti = $pages->find("template=progetto, progetto_cliente=$page, progetto_fornitori=$fornitore");
   if ($progetti != '') echo '<a class="item_dx_a ajax-link" href="'.$fornitore->url.'">'.$fornitore->title.'  -  '.$progetti->count.'</a>';
}

Thank you very much for the aid.

 

Link to comment
Share on other sites

If you only need the count of $progretti then you can use the more efficient $pages->count() method.

And you might find the Connect Page Fields module useful to create two-way connections between the pages in your Page Reference fields. This can help avoid the need for additional PageFinder queries inside the foreach because the projects for each supplier can be stored in a Page Reference field in the supplier template.

Also, please use code blocks when posting code in the forum to make it more readable.

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.
×
×
  • Create New...