Peter Knight Posted February 12, 2018 Share Posted February 12, 2018 On the road and typing on mobile. Hope this makes sense... I have a loggedin user (current session) I want to display to that user some values from the their most recently created page (singular) Is this the right direction to be looking?http://cheatsheet.processwire.com/users/users-methods/users-find-selector/ Thanks Link to comment Share on other sites More sharing options...
kixe Posted February 12, 2018 Share Posted February 12, 2018 $mostRecentlyCreatedPageByUser = $pages->get("created_users_id=$user->id,sort=-created"); 2 Link to comment Share on other sites More sharing options...
Peter Knight Posted February 12, 2018 Author Share Posted February 12, 2018 57 minutes ago, kixe said: $mostRecentlyCreatedPageByUser = $pages->get("created_users_id=$user->id,sort=-created"); Thanks @kixe Couple of questions for you Do I need the sort in there? I'm only trying to retrieve values from the single last created page. I've tried the following which outputs nothing <?php $mostRecentlyCreatedPageByUser = $pages->get("created_users_id=$user->id,sort=-created"); ?> <!-- START: Information --> <strong>City:</strong><?=$mostRecentlyCreatedPageByUser->city ?> <br/> <strong>Miles:</strong><?=$mostRecentlyCreatedPageByUser->miles ?> Link to comment Share on other sites More sharing options...
kixe Posted February 12, 2018 Share Posted February 12, 2018 (edited) @Peter Knight Yes, you have to add 'sort = -created' otherwise you will get 'sort=id' by default. In contrast to find(), get() returns only a single page (the first page from the PageArray to which your selector applies). If you get nothing, the user has not yet created a page or the user is the guest user (not loggedin), or the page have the status hidden or unpublished. You can add selectors like include=hidden|unpublished|all. Edited February 12, 2018 by kixe see next post by kongondo 1 Link to comment Share on other sites More sharing options...
kongondo Posted February 12, 2018 Share Posted February 12, 2018 6 minutes ago, kixe said: You can add selectors like include=hidden|unpublished|all. Not necessary since he's using get(), which assumes these things already . http://processwire.com/api/selectors/#access_control 2 Link to comment Share on other sites More sharing options...
Peter Knight Posted February 13, 2018 Author Share Posted February 13, 2018 Thanks for the help @kixe and @kongondo I got it working with a small change. It only works when add the name of the template to the selector. <?php $mostRecentPage = $pages->get("created_users_id=$user->id, sort=-created, template=places");?> Luckily in this project, my clients only create pages based on this template. 1 Link to comment Share on other sites More sharing options...
kixe Posted February 13, 2018 Share Posted February 13, 2018 @Peter Knight Good that it works. It is always best practice to choose the selector in a way that the mysql query is as accurate as possible and thus fast.I'm still surprised that the original selector returns nothing. Link to comment Share on other sites More sharing options...
Peter Knight Posted February 13, 2018 Author Share Posted February 13, 2018 2 minutes ago, kixe said: @Peter Knight I'm still surprised that the original selector returns nothing. Yep same here. Not sure if it's a bug or intentional. I might file it on GitHub Link to comment Share on other sites More sharing options...
kixe Posted February 13, 2018 Share Posted February 13, 2018 Quick check debug mode on? any warnings, notices, errors? does $mostRecentlyCreatedPageByUser->id return something > 0? is $mostRecentlyCreatedPageByUser->city and $mostRecentlyCreatedPageByUser->miles populated? You should check the latter 2 in your template before echo. 1 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