Title: Using EM shortcodes in php context
Last modified: August 21, 2016

---

# Using EM shortcodes in php context

 *  Resolved [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * (@freakzone89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/)
 * hey guys,
 * i designed a single page using php-code on it. now i want to display different
   event-categories depending on different user-roles and therefore i want to use
   shortcode from event-manager. but unfortunately it doesn’t work. could anybody
   help?
 * this is what i’ve got so far:
 *     ```
       <?php
       if ( user_role_check( 'd1' )):
   
          echo do_shortcode('[events_list category="8"]') ; 
   
        elseif ( user_role_check( 'd2' )): 
   
          echo do_shortcode('[events_list category="9"]');
   
        elseif... //and so on
   
        endif;
       ?>
       ```
   
 * cheers
 * p.s.: the user-roles are added by myself, so they aren’t standard – but this 
   doesn’t seem to be the problem
 * [http://wordpress.org/plugins/events-manager/](http://wordpress.org/plugins/events-manager/)

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

 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089217)
 * Hi,
 * If you put
 * `echo do_shortcode('[events_list category="8"]') ;`
 * outside of the _if_ statements does it work?
 *  Thread Starter [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * (@freakzone89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089231)
 * i tried it but it doesn’t work!
 *  Plugin Author [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089269)
 * how about just
 * `echo do_shortcode('[events_list]') ;`
 * if not, then make sure you’re adding your code to the right place
 *  Thread Starter [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * (@freakzone89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089406)
 * i first tried this, to prove that the combination of the if statements work, 
   and it does!
 *     ```
       if ( user_role_check( 'd1' )):
   
          echo 'd1' ; 
   
        elseif ( user_role_check( 'd2' )): 
   
          echo 'd2';
   
         elseif ( user_role_check( 'h1' )):
   
           echo 'h1';
   
          elseif ( user_role_check( 'h2' )):
   
            echo 'h2';
   
          elseif ( user_role_check( 'admin' )):
   
             echo 'admin;
   
        endif;
       ```
   
 * now i tried it Marcus’ way and changed it to:
 *     ```
       if ( user_role_check( 'd1' )):
   
          echo 'd1' ; 
   
        elseif ( user_role_check( 'd2' )): 
   
          echo 'd2';
   
         elseif ( user_role_check( 'h1' )):
   
           echo 'h1';
   
          elseif ( user_role_check( 'h2' )):
   
            echo 'h2';
   
          elseif ( user_role_check( 'admin' )):
   
             echo do_shortcode('[events_list]');
   
        endif;
       ```
   
 * and it doesn’t work. i just changed the admin position as i’m working as an admin
   and to minimize the potential error sources. i think the code is also positioned
   the right way.
 * any other ideas?
 * cheers
 *  Plugin Author [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089409)
 * try
 * `echo EM_Events::output();`
 * that should definitely work… otherwise something else is going wrong
 *  Thread Starter [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * (@freakzone89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089429)
 * yes, it does work. but it doesn’t fulfill the need of showing a seperate category
   of events.
 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089430)
 * sorry, can you give us more details about this? eg. do you want it to group per
   category
 *  Thread Starter [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * (@freakzone89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089431)
 * i want to show a group of events that belongs to a certain event-category. for
   example users with role “h1” should only see events from category 8 and users
   with role “d2” should only see events from category 7 and so on.
    so i need the
   code to only show events from a certain category.
 * hope that’s the information you need.
 *  [Philip John](https://wordpress.org/support/users/philipjohn/)
 * (@philipjohn)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089441)
 * Hiya,
 * If you take a look at the output() function in the EM_Events class you will see
   a number of options you can provide as parameters, including specifying a category.
 * Thanks,
    Phil
 *  Thread Starter [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * (@freakzone89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089445)
 * oh yeah!
 * this is how it works, thank you phil! instead of
    `echo do_shortcode('[events_list
   category="8"]') ;` i used `echo EM_Events::output( array('category'=>8)) ;`
 * cheers

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

The topic ‘Using EM shortcodes in php context’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [connection](https://wordpress.org/support/topic-tag/connection/)
 * [event](https://wordpress.org/support/topic-tag/event/)
 * [manager](https://wordpress.org/support/topic-tag/manager/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 10 replies
 * 5 participants
 * Last reply from: [freakzone89](https://wordpress.org/support/users/freakzone89/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/using-em-shortcodes-in-php-context/#post-4089445)
 * Status: resolved