Matt Cohen Posted May 19, 2016 Share Posted May 19, 2016 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 More sharing options...
adrian Posted May 19, 2016 Share Posted May 19, 2016 Try: created_users_id= as the selector, rather than user. 2 Link to comment Share on other sites More sharing options...
netcarver Posted May 19, 2016 Share Posted May 19, 2016 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. 3 Link to comment Share on other sites More sharing options...
Matt Cohen Posted May 19, 2016 Author Share Posted May 19, 2016 Try: created_users_id= as the selector, rather than user. This worked perfectly! Thank you Link to comment Share on other sites More sharing options...
adrian Posted May 19, 2016 Share Posted May 19, 2016 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 1 Link to comment Share on other sites More sharing options...
szabesz Posted May 20, 2016 Share Posted May 20, 2016 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 More sharing options...
szabesz Posted May 20, 2016 Share Posted May 20, 2016 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 More sharing options...
netcarver Posted May 20, 2016 Share Posted May 20, 2016 @szabesz, Works fine on 3.x for me. 1 Link to comment Share on other sites More sharing options...
szabesz Posted May 20, 2016 Share Posted May 20, 2016 @netcarver: Thanks, I'll check it out then. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now