Jump to content

User - display field values from their most recent created page


Peter Knight
 Share

Recommended Posts

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

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

@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 by kixe
see next post by kongondo
  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
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...