admin管理员组

文章数量:1122833

I have a working shortcode, ie like this:

[shortcode_name search="" show="url, color, size"]

In this shortcode if I insert for example an email inside search (search="[email protected]") it displays all entries from that e-mail. If I don't write anything, it displays all entries from all e-mails.

I would like to insert a variable like search="'.$user_email.'" to display all entries of that logged user.

How can I use that variable?

I tried also with a shortcode that generates the e-mail, but how to use a shortcode inside another shortcode? I tried [shortcode_name search="[user_email_shortcode]" show="url, color, size"] but of course it doesn't work.

I have a working shortcode, ie like this:

[shortcode_name search="" show="url, color, size"]

In this shortcode if I insert for example an email inside search (search="[email protected]") it displays all entries from that e-mail. If I don't write anything, it displays all entries from all e-mails.

I would like to insert a variable like search="'.$user_email.'" to display all entries of that logged user.

How can I use that variable?

I tried also with a shortcode that generates the e-mail, but how to use a shortcode inside another shortcode? I tried [shortcode_name search="[user_email_shortcode]" show="url, color, size"] but of course it doesn't work.

Share Improve this question asked Feb 5, 2021 at 15:12 KaiKai 412 bronze badges 2
  • Is [shortcode_name] created by you? If not, are you able to create your own shortcodes? (You could just create a [shortcode_name_loggedIn] that basically returns the other shortcode with the email pre-filled) – kero Commented Feb 5, 2021 at 15:18
  • You can't put shortcodes inside the attributes of other shortcodes, it will break the parsing and neither shortcode will work, regardless of what code you run when the shortcode is processed ( because it never finds the shortcode correctly to process it ). This approach is a dead end, you will need to find alternative solutions, e.g. a new shortcode that combines the two in PHP code – Tom J Nowell Commented Feb 5, 2021 at 15:45
Add a comment  | 

1 Answer 1

Reset to default 1

apparently I found the solution (thanks to amatorpl), if anyone needs it:

function show_history() {

$user = wp_get_current_user();
$user_email = $user->user_email;

$show_history = '[shortcode_name search="'.$user_email.'" show="url, color, size"]';
$history =  do_shortcode($show_history);

return $history;
}

add_shortcode('show_history', 'show_history'); 

Thanks for the try

本文标签: Variable inside shortcode or shortcode inside shortcode