Title: shortcode in php with php inside
Last modified: August 30, 2016

---

# shortcode in php with php inside

 *  Resolved [Exilant](https://wordpress.org/support/users/exilant/)
 * (@exilant)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-in-php-with-php-inside/)
 * Hi Eliot!
 * I`m trying something pretty strange with my fantasy-php logic, and struggled 
   the last weeks around with it, but somehow i don`t get it.
 * What i basicly try is to put your shortcode in a php file, and php inside of 
   it..
 * `<?php echo do_shortcode('[users include="' . $usrval . '"][user avatar][/users]');?
   >`
 * why i try this..
    ——————————————————— i made a frontend-edit template to edit
   the posts.. there will be some different work-steps with templates to edit it,
   until its finished. To prevent, that 2 users are working on the same project,
   i made a custom field, called “user” – a part in the form sets the user id in
   the custom field, it looks like this:
 *     ```
       <textarea id="user" name="user" value="<?php echo $value; ?>">
       <?php global $current_user;
             get_currentuserinfo();
   
             echo '' . $current_user->ID . "\n";
       ?>
         </textarea>
       ```
   
 * **at the top of the page, i update the field and set it to $usrval**
    ——————————————————————-
 *  ` wp_update_post($post);
 *  if ( isset($_POST[‘user’]) ) update_post_meta($post_id, ‘user’, esc_sql($_POST[‘
   user’]), $usrval = get_post_meta($post->ID, ‘user’, true) );`
 * **later, i tried to set it in the get post meta.. it worked, but $usrval was 
   for some reason evrywhere..**
    ———————————————————————-
 *     ```
       <?php
       //$usrval = get_post_meta($post->ID, 'user', true);
       $user_info = get_userdata(  print($usrval) );
             echo 'Username: ' . $user_info->user_login . "\n";
             echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
             echo 'User ID: ' . $user_info->ID . "\n";
       ?>
       ```
   
 * so, i tried to use custom content shortcode with php to display it in the posts
   loop of my page.. this point..
 * `<?php echo do_shortcode('[users include="' . $usrval . '"][user avatar][/users]');?
   >`
 * i think its just some ‘ character or something, what went wrong.. but i cant 
   find the reason, and my brain is boiling on 200 degree : / could you please take
   a look? i know, its a strage question, and the way i did all this is maybe stupid..
   i have nearly no idea of php, its just working with fantasy.. ^^*
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Exilant](https://wordpress.org/support/users/exilant/)
 * (@exilant)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-in-php-with-php-inside/#post-6695096)
 * aaaah, i did it directly ^^* sorry for the question..
 * if somebody else should have this problem, do it like this:
 * <?php echo do_shortcode(‘[users include=”‘ .get_post_meta($post->ID, ‘user’, 
   true). ‘”][user avatar][/users]’ );?>
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-in-php-with-php-inside/#post-6695120)
 * > my brain is boiling on 200 degree..
 * Heheh, I know we’ve all been in that situation before. I’m glad to hear you solved
   it.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘shortcode in php with php inside’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-in-php-with-php-inside/#post-6695120)
 * Status: resolved