Problem: I have a conditional that tests the current User against the author of a post. The conditional works in the context of a post, but I would like to use the same conditional in another page where the post ID is set by a URL parameter.
Solution: You could use a custom shortcode like this instead:
[wpv-conditional if="('[wpv-current-user info='user_login']' eq '[author_login_from_post_id_param]')"] Content 2 [/wpv-conditional]
Add this code to your child theme's functions.php file:
function author_login_from_post_id_param_func($atts) { $postid = isset($_GET['postid']) ? $_GET['postid'] : 0; $thepost = $postid ? get_post($postid) : 0; $author = $thepost ? $thepost->post_author : 0; $login = $author ? get_the_author_meta('user_login', $author) : ''; return $login; } add_shortcode("author_login_from_post_id_param", "author_login_from_post_id_param_func");
Then go to Toolset > Settings > Frontend Content and register author_login_from_post_id_param in the third-party shortcodes section.
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 7 months ago.
Assisted by: Christian Cox.