Skip Navigation

[Resolved] Show "edit" for logged in user on own post

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to show some content, only when the currently logged-in visitor is also the current post's author.

Solution:

Shared information about the "wpv-post-author" and "wpv-user" shortcodes and using them in the conditional display.


[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-user field="ID"]' )"] 
...Content to show...
[/wpv-conditional]

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by marcialB 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1338815

Hi there

I want to display an "edit" link (that leads to an edit post form). But that edit link should only appear when the currently logged in user is visiting his own posts.

Example: User A creates Post X and Y. User B creates post Z. If user A visits Z, there is no edit link. If user A goes to post X or Y, the edit link appears for him. User B however only sees that link when visiting post Z.

I tried to use access, but as far as I understand, it's not possible to use access on user level. Therefore I tried to "hack" a view where I limit the results by restricting it to the current user (--> Select posts with the author the same as the current logged in user) and show the link in there. However, that doesn't work. I assume I'm doing it wrong.

Thanks for your help!

Best,
Marcial

#1339365

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Marcial,

Thank you for contacting us and I'd be happy to assist.

You can get the ID of the current post's author, using the "wpv-post-author" shortcode:
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author )


[wpv-post-author format="meta" meta="ID"]

Likewise, you can get the ID of the currently logged-in user, using the "wpv-user" shortcode:
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user )


[wpv-user field="ID"]

To show an edit link (or any content) in currently logged-in user's own posts only, you can use these two shortcodes, inside a conditional display block like this:
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/ )


[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-user field="ID"]' )"] 
Edit link code
[/wpv-conditional]

As a result, the edit link will only show when the current post's author ID and the currently logged-in user's ID, are the same.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1339425

Hi Waqar

Thank your very much for your reply and explanation.

Best,
Marcial

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.