Jump to content

Returning list of pages belong to a list of users


Matt Cohen
 Share

Recommended Posts

Hi there, I am having a trouble with my selector. I'm wanting to return a list of pages that belong to a template and a particular user. However not returning any results.

 Here is my code

<?$lostproperty = $pages->find("user=matt, template=lost-property");

                      foreach ($lostproperty as $items) {

                        echo "<td><a href='$items->url'>$items->id </a></td>";
                        echo "</td>";
                       
                        echo "<td>";
                        echo $items->modifiedUser->name;
                        echo "</td>";

                        echo "<td>";
                        echo date("d/m/y H:i", $items->created);                     echo "</td>";
                        echo "</td>";
                        echo "<td>";
                        echo "$items->lp_city";
                        echo "</td>";
                        echo "<td>$items->lp_row";
                        echo "</td>";
                        echo "<td> $items->lp_item";
                        echo "</td>";
                         echo "<td > $items->lp_description";
                        echo "</td>";
                         echo "<td style='text-transform:capitalize'> $items->lp_contactname";
                        echo "</td>";
                         echo "<td style='text-transform:capitalize'> $items->lp_contact";
                        echo "</td>";
                         echo "<td> $items->lp_ro";
                        echo "</td>";
                         echo "<td> $items->lp_status";
                        echo "</td>";

                        echo "</tr>";
                      }
                      ?>
Link to comment
Share on other sites

Did you remember to get the id of the user whose name is matt and use that in the selector?

You could do:

$lostproperty = $pages->find("created_users_id=".$users->get("matt")->id.", template=lost-property");

Otherwise, make sure your template is correct.

Also, to avoid confusion, I would go with $item instead of $items

  • Like 1
Link to comment
Share on other sites

You could do:
$lostproperty = $pages->find("created_users_id=".$users->get("matt")->id.", template=lost-property");

Just to highlight some recent additions to our toolbox – from ProcessWire 3.0.13 and up – we can construct our selectors by using arrays too:

https://processwire.com/blog/posts/processwire-3.0.13-selector-upgrades-and-new-form-builder-version/#selector-engine-array-support

Link to comment
Share on other sites

Hi Matt,

I find nik's Selector Test module to be really useful when developing selectors. If you ever have a selector that isn't doing what you expect, it can really help. Highly recommended.

Thanks netcarver! Since you recommend it, does it mean that it just works fine in ProcessWire 3.x too? I can imagine that it does not implement anything fancy that might be deprecated, but I have never used it so I thought I ask before wasting some time on it :)

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