Home › Toolset Professional Support › [Resolved] Unable to hide post edit link from non-authors using shortcode
Problem:
I want to hide the edit post link from non authors along with other data.
Solution:
You can try wpv-conditional shortcode like this:
Relevant Documentation:
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/Hong_Kong (GMT+08:00)
Tagged: Views plugin
This topic contains 8 replies, has 2 voices.
Last updated by himanshuS 3 years, 11 months ago.
Assisted by: Luo Yang.
I want to hide the edit post link from non authors along with other data. I am using the following shortcode:
[wpv-conditional if="( [wpv-post-author format='meta' meta='id'] eq [wpv-current-user format='meta' info='id'] )"]
Current User is post author[/wpv-conditional]
But the code does not work.
Am I missing something here?
Reference post: https://toolset.com/forums/topic/how-to-show-toolset-edit-post-link-for-only-admin-and-post-owner/
Hello,
Please try to modify the shortcodes as below:
[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-current-user info="id"]' )" ] Current User is post author [/wpv-conditional]
And test again.
More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-current-user
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-author
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional
I tried this:
[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-current-user info="id"]' )" ]
Current User is post author
[/wpv-conditional]
Still does not work. Image uploaded.
I have tried above codes in my localhost with a fresh WP installation + the latest version of Toolset Blocks plugin, it works fine,
Please check these:
1) Make sure you are using the latest version of Toolset plugins(especially the Toolset Blocks plugin), you can download them here:
https://toolset.com/account/downloads/
2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2020, and test again
You can provide your website credentials in below private message box, also point out the problem page URL.
Thanks for the details, I can login your website, but it seems you are also working on that elementor, please update here when your website is ready for debug.
You can take control now. I gave control for that page to you.
It seems that elementor shortcode widget does not support shortcode within shortcode feature, but there is a workaround, I have setup a demo in your website:
1) Create a content template, display the same shortcode:
hidden link
[wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' eq '[wpv-current-user info="id"]' )" ] Current User is post author [/wpv-conditional] [wpv-conditional if="( '[wpv-post-author format="meta" meta="ID"]' ne '[wpv-current-user info="id"]' )" ] Current User is not post author [/wpv-conditional]
2) Display above content template in elementor template:
[wpv-post-body view_template="test-ct"]
Please test again, check if it is fixed, thanks
Thanks Luo. That works. Although I found a less complicated solution by writing my own shortcode.
<?php global $wpdb;
$current_user = get_current_user_id();
global $post;
$author_id = $post->post_author;
$output = 0;
If($current_user == $author_id)
{ $output = 1;
}
echo $output;
?>
My issue is resolved now. Thank you!