I thought I'd quickly write this up as I have read countless posts on how to do this and none of them were nearly detailed enough to help me i.e. create filter 'current user', all well and good but that option is not in the filter list in views until you create a relationship first.

So here's how to list a users OWN posts (all content types) with a link called 'View your posts' which only displays when a user is logged in.

1) Add new view, view name 'View own posts'
2) Show 'content' of type 'all'
3) Create a page - yes, path will automatically be 'view-own-posts'
4) Create a menu link - yes, menu = user menu, title = 'View own posts'

Continue and edit

Now, if you click add filter criteria now you'll see the user section at the bottom of the checkbox list contains only:

User: Authentication module
User: Authentication name
User: Authmap ID
User: Roles

So, step 5) Add relationship - Content: Author
6) Tick the box 'Require this relationship'

Now, go back to add filter and look at the user section at the bottom of the checkbox list:

User: Active
User: Authentication module
User: Authentication name
User: Authmap ID
User: Created date
User: Current
User: E-mail
User: Language
User: Last access
User: Last login
User: Name
User: Name (raw)
User: Picture
User: Roles
User: Signature

That's more like it!

7) Tick the box 'User: Current' and select the radio button 'Is the logged in user' - yes
8) Under 'page settings' in the main views page where it says Access: 'Permission', click on permission
9) Change that to radio button 'Role'
10) Check the box 'authenticated user' (so menu item doesn't show up when people are not logged in)
11) Add 'No results behavior' of global text area (this is for people who may be logged in but haven't created any posts and the result when they click on 'View own posts')
12) For example, I put in 'You haven't posted anything yet. Click on 'Add content' to get going!'

13) So, logged in users who have posted clock the link and get their posts, logged in users without posts get the message in (12) above.

In theory it would perhaps be better that if a user has no posts then the link doesn't show up at all, but I don't know how to do that yet.

I hope this helps someone else trying to achieve the same/similar thing.

Comments

samwillc’s picture

What I'm trying to do is extend this a bit to have a page title of 'Posts by [username]' when a user clicks on the 'View my posts' link rather than the stock title of 'View own posts'.

I have tried changing the url path to 'view-own-posts/%' and adding a contextual filter of 'User: Name' but I get an SQL error and a few other combinations but still no joy. I'm not sure how to do this as I don't fully understand how to use contextual filters or getting information from the url, if anyone can help that would be very appreciated.

Thanks.