Title: Set php variables in shortcode
Last modified: August 22, 2016

---

# Set php variables in shortcode

 *  Resolved [kceall](https://wordpress.org/support/users/kceall/)
 * (@kceall)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/set-php-variables-in-shortcode/)
 * I have created my page in .php and I am trying to set a variable depending on
   the user role but the code seems to just show up on the page.
 * the code is something like this inside php tags:
 * `echo do_shortcode('[O_U user_role="myCustomUserGroup"] $var = $wpdb->get_results("
   query"); ?>[/O_U]');`
 * [https://wordpress.org/plugins/user-specific-content/](https://wordpress.org/plugins/user-specific-content/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Bainternet](https://wordpress.org/support/users/bainternet/)
 * (@bainternet)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/set-php-variables-in-shortcode/#post-5226483)
 * Your PHP string is wrong buddy

Viewing 1 replies (of 1 total)

The topic ‘Set php variables in shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/user-specific-content_ffffff.svg)
 * [User Specific Content](https://wordpress.org/plugins/user-specific-content/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-specific-content/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-specific-content/)
 * [Active Topics](https://wordpress.org/support/plugin/user-specific-content/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-specific-content/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-specific-content/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Bainternet](https://wordpress.org/support/users/bainternet/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/set-php-variables-in-shortcode/#post-5226483)
 * Status: resolved